Skip to content
Advertisement

Multidimensional PHP array – Key exists

I want a function that will return TRUE or FALSE based on if a given key exists in a multidimensional array in PHP.

I haven’t been able to figure out a recursive function to perform this action.

A sample of what this could do:

JavaScript

Advertisement

Answer

This is where a recursive function comes in handy.

JavaScript

Note that this can take some time (in long nested arrays), it might be better to flatten first, since you are only interested in whether the key exists or not.

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