I have a large multidimensional array. And I have to find a specific sub-array from it.
I tried using a single recursion function, but did not actually return a value. Can anyone give me another solution.
Here is a preview of the array.
Array ( [0] => Array ( [expanded] => 1 [key] => _1 [title] => New ) [1] => Array ( [key] => _2 [title] => Home ) [2] => Array ( [expanded] => 1 [key] => _3 [title] => Care [children] => Array ( [0] => Array ( [expanded] => 1 [key] => _4 [title] => face [children] => Array ( [0] => Array ( [key] => _5 [title] => new ) [1] => Array ( [key] => _6 [title] => <strong>face timeline</strong> [data] => Array ( [url] => http:
From this array I want this array (below):
Array ( [key] => _6 [title] => <strong>face timeline</strong> [data] => Array ( [url] => http:
Here is what I tried
function recursion($array,$postid) { foreach ($array as $key=>$value) { if((isset($value['data']['cid'])) && ($value['data']['cid'] == $postid)){ $tmp = $value; return $value; } if (is_array($value)) { recursion($value,$postid); } } }
This function does not return a value.
Here $postid is 2291 . This is what I am looking for, and I can print this array, but cannot return the value. Here is the link
user5147795
source share