I am using array_walk_recursive with a callback function to search within a nested array for specified key:
array_walk_recursive($array, array($this, 'walk_array'), $key);
Here is the callback function:
function walk_array($value, $key, $userdata = '')
{
if ($key === $userdata)
{
self::$items_array[$key] = $value;
echo $value . "<br />\n";
}
}
The problem is that I can not find a way to store/return the found elements from the callback function even though I am using static variable $items_array but it always contains the last item processed by the array_walk_recursive. On the other hand, if I echo the found elements from callback function:
echo $value . "<br />\n";
All found elements are echoed fine.
How do I return or store the found elements from the callback function?