note 49107 added to function.array-walk

From: Date: Mon, 17 Jan 2005 02:27:16 +0000
Subject: note 49107 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-83474@lists.php.net to get a copy of this message
As well as being able to pass the array the callback will be working on by reference, one can pass the optional userdata parameters by reference also: <?php function surprise($x,$key,$xs) { //$key is unused here. $x.='!'; array_push($xs,$x); } $array1 = array('this','that','the other'); $array2 = array(); array_walk($array1,'surprise',&$array2); print_r($array1); print_r($array2); ?> Of course, that precise example would be better handled by array_map, but the principle is there. ---- Manual Page -- http://www.php.net/manual/en/function.array-walk.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+49107 Delete -- http://master.php.net/manage/user-notes.php?action=delete+49107&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49107&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+49107&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+49107&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+49107&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+49107&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+49107&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#83474) next »