php - array_walk_recursive return value -
i using array_walk_recursive callback function search within nested array specified key:
array_walk_recursive($array, array($this, 'walk_array'), $key); here callback function:
function walk_array($value, $key, $userdata = '') {     if ($key === $userdata)     {         self::$items_array[$key] = $value;         echo $value . "<br />\n";     } } the problem can not find way store/return found elements callback function though using static variable $items_array contains last item processed array_walk_recursive. on other hand, if echo found elements callback function:
echo $value . "<br />\n"; all found elements echoed fine.
how return or store found elements callback function?
if $key going correspond multiple values in nested arrays walk through, $item_arrays should have own array key. otherwise, you're doing overwriting self::$items_array[$key] every value comes by.
try this:
self::$items_array[$key][] = $value; 
Comments
Post a Comment