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
2
votes
1 answer

Array Intersect in the same order PHP

I have 2 arrays: $array1 = array("1","2","3","4","5"); $array2 = array("7","2","3","1","5"); What I want to do is match the values in $array1 and $array2 strictly in order. The desired output should be 2, 3 and 5 since 1 is not in the same order.…
2
votes
2 answers

Use array_filter() or array_intersect() to filter 2-dimensional array by one column using a 1-dimensional array

I'm trying to filter my first array by my second array. I want to filter every person whose age is 22,25,35, or 40. I have these whitelisted values store in an $a2 $a1 = [ ['name' => 'mike', 'age' => 18], ['name' => 'james', 'age' =>…
2
votes
2 answers

Find value from multidimensional array from given two values

I have the following array. Array ( [0] => Array ( [product] => p1 [item] => q1 [date] => d1 [status] => N ) [1] => Array ( [product] => p2 …
2
votes
3 answers

PHP : array_intersect not giving expected result

I am trying to count the matches between expected and actual in a PHP array, I have this... $array = array( "item" => array( 'expected' => array( '1' => 25, '2' => 4, '3' => 4, ), …
fightstarr20
  • 11,682
  • 40
  • 154
  • 278
2
votes
3 answers

Find intersecting rows between two 2d arrays comparing differently keyed columns

I have two arrays, The $first has 5000 arrays inside it and looks like: array( array('number' => 1), array('number' => 2), array('number' => 3), array('number' => 4), ... array('number' => 5000) ); and the $second has 16000 rows and…
Hailwood
  • 89,623
  • 107
  • 270
  • 423
2
votes
5 answers

Keep array rows where a column value is found in a second flat array

** I have edited this to show how I got my code to work using array_search I have an array, $arr1 with 5 columns as such: key id name style age whim 0 14 bob big 33 no 1 72 jill big 22 yes 2 39 sue …
ian
  • 303
  • 3
  • 15
2
votes
2 answers

How to know the pair of key that return from array_intersec

I have these array : $a = ['a','b','c','d','e','f']; $b = ['d','e','f']; if I use array_intersect to the array above like, $c = array_intersect($a, $b); $d = array_intersect($b,$a); $c will return : Array ( [3] => d [4] => e [5] =>…
punk73
  • 378
  • 2
  • 12
2
votes
2 answers

Php Array sorting assoc key after intersect key

Currently I have this: $pattern = array('industry_id','category_id','subcategory_id'); $data = array('advert_id' => string '261501' (length=6) 'advert_type_id' => string '7' (length=1) 'user_id' => string '6221' (length=4) 'industry_id' =>…
Drixson Oseña
  • 3,631
  • 3
  • 23
  • 36
2
votes
1 answer

Invalid operand type was used: array_uintersect expects array(s)

I have the following code that get the intersection on a variable amount of arrays. $intersection = call_user_func_array('array_uintersect', $params); Using test data, this works very well. However, when using real data (which is a much larger data…
Raphael Rafatpanah
  • 19,082
  • 25
  • 92
  • 158
2
votes
1 answer

PHP multi dimensional array intersect

I've written this code:
upndown
  • 25
  • 5
2
votes
1 answer

How to compare arrays with different sizes

I want to compare 2 arrays, except the two arrays may sometimes be of different sizes. For example, I have a form and I receive the values with this: // The post send more values than other array: // name , email , password, phone , address //…
2
votes
2 answers

array_intersect throws errors when arrays have sub-arrays

I'm trying to use array_intersect to compare two arrays of arrays. $start[]=array( 'id'=>1, 'name'=>'Up', 'action'=>'up' ); $start[]=array( 'id'=>3, 'name'=>'Down', 'action'=>'down' ); $start[]=array( …
Force Flow
  • 714
  • 2
  • 14
  • 34
2
votes
2 answers

PHP array_intersect() till the first match

I have 2 arrays to compare and find if there is at least a single value in common. This works just fine: $arr1 = array(1, 2, 3, 4, 5); $arr2 = array(2, 3, 4, 5, 6); if (array_intersect($arr1, $arr2)) { // good, at least one match…
Geo
  • 12,666
  • 4
  • 40
  • 55
2
votes
2 answers

trying to match a value in two arrays, if a matched value is present then output true

trying to match a value in two arrays, if a matched value is present then output true, thinking maybe the array_intersect function? very unsure! Any help is much appreciated! Basically have two sql queries which i cant quite fit into this box! but…
Findlay Mack
  • 25
  • 1
  • 4
2
votes
0 answers

Intersect array empty value if it will not be executed

if the array $same_white_pemasang or $same_black_pemasang empty value, then the return value will be ignored? for $implodeWhiteJenisPemasang $inputWhiteJenisPemasang = $verifikator['whiteJenisPemasang']; $dataWhiteJenisPemasang = array(); foreach…
user1798945
  • 145
  • 1
  • 2
  • 7
1 2
3
11 12