note 124036 added to function.array-walk-recursive

From: Date: Sat, 13 Jul 2019 16:32:13 +0000
Subject: note 124036 added to function.array-walk-recursive
Groups: php.notes 
Request: Send a blank email to php-notes+get-211553@lists.php.net to get a copy of this message
Here's a more general solution to modifying the array to which the leaf belongs. You can unset the current key, or add siblings, etc. <?php /** * Modified version of array_walk_recursive that passes in the array to the callback * The callback can modify the array or value by specifying a reference for the parameter. * * @param array The input array. * @param callable $callback($value, $key, $array) */ function array_walk_recursive_array(array &$array, callable $callback) { foreach ($array as $k => &$v) { if (is_array($v)) { array_walk_recursive_array($v, $callback); } else { $callback($v, $k, $array); } } } ?> ---- Server IP: 208.43.231.9 Probable Submitter: 82.199.157.34 (proxied: 198.27.234.28) ---- Manual Page -- http://php.net/manual/en/function.array-walk-recursive.php Edit -- https://master.php.net/note/edit/124036 Del: integrated -- https://master.php.net/note/delete/124036/integrated Del: useless -- https://master.php.net/note/delete/124036/useless Del: bad code -- https://master.php.net/note/delete/124036/bad+code Del: spam -- https://master.php.net/note/delete/124036/spam Del: non-english -- https://master.php.net/note/delete/124036/non-english Del: in docs -- https://master.php.net/note/delete/124036/in+docs Del: other reasons-- https://master.php.net/note/delete/124036 Reject -- https://master.php.net/note/reject/124036 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#211553) next »