Recursive array search I've got a plugin where I've written a simple recursive array search to find an array within a nested/multidimensional array which contains a certain value.

private function arraySearch($haystack,$needle,$depth = 1)
{
    foreach($haystack AS $key =&gt; $value) {
        if (is_array($value) &amp;&amp; array_key_exists('title',$value) &amp;&amp; strtolower($value['title']) == strtolower($needle)) {
            return $value;
        } elseif(is_array($value)) {
            $depth++;
            $this-&gt;arraySearch($value,$needle,$depth);
        }
    }
}


With some logging within this function I can see that it works and returns at the correct time but when I call it in my plugin methods the response is empty.

For example, if I wanted to get an array which contains a title key and the value for this is venue, I'd type: 

$result = $this-&gt;arraySearch($array,'Venue');


Applied to the following array:

Array
(
    [pages] =&gt; Array
        (
            [0] =&gt; Array
                (
                    [elements] =&gt; Array
                        (
                            [0] =&gt; Array
                                (
                                    [type] =&gt; text
                                    [isRequired] =&gt; 1
                                    [name] =&gt; question1
                                    [title] =&gt; Venue
                                )

                            [1] =&gt; Array


So this should return the array $array['pages'][0]['elements][0] but $result` seems to be empty.

Any suggestions?

Cole
This line:

$this-&gt;arraySearch($value,$needle,$depth);


should be

return $this-&gt;arraySearch($value,$needle,$depth);