Questions tagged [array-intersect]

PHP's array_intersect() function accepts the array with master values to check, an array to compare values against and a variable list of arrays to compare. It returns an array containing all of the values in master array whose values exist in all of the parameters.

PHP's array_intersect() function accepts the array with master values to check, an array to compare values against and a variable list of arrays to compare. It returns an array containing all of the values in master array whose values exist in all of the parameters.

169 questions
1
vote
1 answer

How can I compute the intersection of an unknown number of arrays in php?

I have an array of arrays, and I want to find the intersection of the contained arrays. My problem is that the array_intersect function requires the arrays to be explicitly specified in the params. I cannot feed the function with my…
kaklon
  • 2,422
  • 2
  • 26
  • 39
1
vote
3 answers

array_uintersect() gives unexpected results when callback only returns 0 or 1

I have a custom callback in my array_uintersect() call because I need to case-sensitively compare strings in two elements while comparing rows between two multi-dimensional arrays. function filterIdenticalEntriesCallback($a, $b) { echo…
KnF
  • 166
  • 10
1
vote
1 answer

array_intersect() on all possible combinations of n number of elements

$a1 = [a,b]; $a2 = [a,c]; $a3 = [d,e]; $a4 = [d,f]; I know using array_intersect() function we can find common element between the arrays So in this case we will do array_intersect($a1,$a2,$a3,$a4), this will return empty array since there is no…
Angiras
  • 13
  • 3
1
vote
1 answer

Get Maximum Intersection as An Aggregate Function in Python

I have a dataframe like below (available in array format or unnest one): team | player | favorite_food A | A_player1 | [pizza, sushi] A | A_player2 | [salad, sushi] B | B_player1 | [pizza, pasta, salad, taco] B | B_player2 |…
1
vote
3 answers

Get quantity-specific intersections between two arrays

For optimisation purposes, I need to intersect two arrays and keep the least number of duplicate values from the two initial arrays in the resulting array. The order of values in the resulting array is not important. Another important constraint is…
1
vote
2 answers

array_uintersect comparing specific element in each row of a multidimensional array against a flat array of strings

Is it possible to compare a string vs. a string one level deeper (in an array) using array_uintersect()? Or will there be some sorting taking place and those params be swapped behind the scenes when serving them to the value compare function…
Mat90
  • 169
  • 1
  • 9
1
vote
3 answers

array_intersect() with 2d arrays in php

I am trying to filter 2d arrays which satisfy two conditions. But, it not works as expected. I figured out that error is in array_intersect() function. Why array_intersect() not works correctly here.Is there another way to do this without…
Ishad
  • 121
  • 1
  • 11
1
vote
1 answer

How to use array_intersect to find the same files?

I have a problem regarding the deletion of two files (both with the same file name) in two diffrent folders. I tried using the unlink function for deletion. How can i delete these two files in these two different folders using PHP unlink…
user13193267
1
vote
2 answers

check mysql result against array for duplicates

I have researched this to no avail and thought I'd inquire here since the group of folks at SO seems to be really well informed. Here's the situation. I have a database in which I've got matches stored to create a result/schedule for a league app…
Rico
  • 37
  • 1
  • 4
1
vote
3 answers

Merge/Append the differences between two 2d arrays to the intersection of the same two arrays to achieve a particular sort order

I have two arrays, the first one is the sorted version (sorted by the user) of the second one, but the second one can be shorter or longer than the first one. For example: $books_sorted = array( 0 => array( "title" => "In Search of Lost…
1
vote
1 answer

php array_intersect don't get the first value

Basically, I'm trying to import csv data to my database. Before insert the data to database I want to check whether database has that column (from csv headers) or not. // read csv from file ex: data.csv $reader =…
1
vote
1 answer

Find intersecting values in multiple numpy arrays

I have 100 large arrays > 250,000 elements each. I want to find common values that are found in these arrays. I know that there are not going to be values that are found in all 100 arrays, but a small number values will be found in multiple arrays…
1
vote
0 answers

Multidimensional array key intersection add value on condition both values are equal in php

I have two multidimensional arrays $array1 = Array ( [a1] => Array ( [a_name] => aaaaa [a_value] => aaa ) [b1] => Array ( [b_name] => zzzzz [b_value] => bbb ) [c1] => Array ( …
1
vote
1 answer

PHP Array Intersection

Maybe someone can help me find the array intersection of a multidemsional array like this one: [attributes] => Array ( [Color] => Array ( [0] => Cool White …
JoeyH
  • 335
  • 2
  • 10
1
vote
1 answer

Removing values from multidimensional array based on multidimentional whitelist

I have the following white list: private $conditionalFieldsWhitelist = [ 'Basic Fields' => [ 'contact_name', 'contact_lastname', ], 'Required Fields' => [ 'some_required_field', ] ]; That I want to run agains…
Bird87 ZA
  • 2,313
  • 8
  • 36
  • 69