note 107997 added to function.array-walk

From: Date: Wed, 21 Mar 2012 10:53:11 +0000
Subject: note 107997 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-186753@lists.php.net to get a copy of this message
To retrieve the userData parameter outside the function, you have to pass it by reference inside an array. <?php $customData = array(); $myArray = array('apple', 'orange', 'banana'); array_walk($myArray, 'myFunction', array(&$customData)); function myFunction(&$item, $index, $data) { $data[0][$index] = strlen($item); // ... } print_r($customData); ?> Output : Array ( [0] => 5 [1] => 6 [2] => 6 ) ---- Server IP: 89.31.146.176 Probable Submitter: 80.13.49.2 ---- Manual Page -- http://www.php.net/manual/en/function.array-walk.php Edit -- https://master.php.net/note/edit/107997 Del: integrated -- https://master.php.net/note/delete/107997/integrated Del: useless -- https://master.php.net/note/delete/107997/useless Del: bad code -- https://master.php.net/note/delete/107997/bad+code Del: spam -- https://master.php.net/note/delete/107997/spam Del: non-english -- https://master.php.net/note/delete/107997/non-english Del: in docs -- https://master.php.net/note/delete/107997/in+docs Del: other reasons-- https://master.php.net/note/delete/107997 Reject -- https://master.php.net/note/reject/107997 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186753) next »