I have an array like this:
Array
(
[2] => Array
(
[0] => name2 surname
[1] => email2@email.com
[2] => 834502034
[3] => image url3
)
[3] => Array
(
[0] => name3 surname
[1] => email2@email.com
[2] => 7648484886
[3] => image url3
)
[0] => Array
(
[0] => name0 surname
[1] => email0@email.com
[2] => 56783658658
[3] => image url0
)
[1] => Array
(
[0] => name1 surname
[1] => email1@email.com
[2] => 7648484886
[3] => image url1
)
)
youll notice that some of the values are the same and may only have a single difference in value.
I need to find out if another single array matches any on of the sub arrays and return the key.
the array I would match against is not multidimensional:
Array
(
[0] => name1 surname
[1] => email1@email.com
[2] => 7648484886
[3] => image url1
)
How do I find out if my single array is found within the main array and return the KEY?
Ive tried using array_diff_uassoc with a callback which returns the non matching key => array and I guess I could then match the count of both results to see if there is a difference, but I still need the key of the matched array. The array I am comparing against will always have the exact values [0],[1],[2] and [3].
array_searchwill do that, taking advantage of how comparing arrays for equality works in PHP (which means that the order of items inside each sub-array and in the array you provide as the search target must be the same!):