note 71901 added to function.array-walk
| From: | jerk at yoosic dot de | Date: | Thu, 21 Dec 2006 16:05:25 +0000 |
| Subject: | note 71901 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-120835@lists.php.net to get a copy of this message | ||
if you want to modify every value of an multidimensional array use this function used here:
<?php
$array = array (1=>1, 2=> 2, 3 => array(1=>11, 2=>12, 3=>13));
$text = "test";
function modarr(&$array, $text) {
foreach ($array as $key => $arr) {
if(is_array($arr)) $res[$key] = modarr(&$arr,$text);
// modification function here
else $res[$key] = $arr.$text;
}
return $res;
}
$erg = modarr($array, $text);
print_r($erg);
?>
result will be_
<?php
Array ( [1] => 1test [2] => 2test [3] => Array ( [1] => 11test [2] => 12test [3]
=> 13test ) )
?>
----
Server IP: 217.13.201.10
Probable Submitter: 212.80.236.184 (proxied: unknown)
----
Manual Page -- http://www.php.net/manual/en/function.array-walk.php
Edit -- https://master.php.net/note/edit/71901
Del: integrated -- https://master.php.net/note/delete/71901/integrated
Del: useless -- https://master.php.net/note/delete/71901/useless
Del: bad code -- https://master.php.net/note/delete/71901/bad+code
Del: spam -- https://master.php.net/note/delete/71901/spam
Del: non-english -- https://master.php.net/note/delete/71901/non-english
Del: in docs -- https://master.php.net/note/delete/71901/in+docs
Del: other reasons-- https://master.php.net/note/delete/71901
Reject -- https://master.php.net/note/reject/71901
Search -- https://master.php.net/manage/user-notes.php