Skip to content
Advertisement

in_array() on multidimensional array

I want to find an array inside an array by its value.

Example: It returns “Match not found”, while “Peter” is inside the $people array. But I can found “Joe”.

JavaScript

How can I found “Peter” in the array?

Advertisement

Answer

Using in_array search for values, but in your code Peter is a key. Then you can use array_key_exists instead:

JavaScript

Output

JavaScript

you can combine both since the name you’re searching is sometimes the value like "Joe" in your example.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement