problem passing arrays by reference using array_walk

From: Date: Mon, 27 Mar 2000 09:51:09 +0000
Subject: problem passing arrays by reference using array_walk
Groups: php.version4 
Request: Send a blank email to php-version4+get-12668@lists.php.net to get a copy of this message
I'm probably being stupid but... I'm trying to pass an array by reference as the third parameter to array_walk, but by the time it arrives at the function named in the second parameter to array_walk, I appear to be dealing with a copy of the array. Here's some simple test code. Array2[0] is initialised to foo. SetArray gets called for key 0 and the current value is shown as "foo". After the assignment, the new value is reported as "bar", but after the array_walk $Array2[0] is reported as still being "foo". function SetArray($Item,$Key,&$Array) { echo("current value=$Array[$Key]<br>"); $Array[$Key]="bar"; echo("new value=$Array[$Key]<br>"); } $Array1[0]="dont care for now"; $Array2[0]="foo"; array_walk($Array1,"SetArray",$Array2); echo($Array2[0]); Outputs: current value=foo new value=bar foo So, am I doing something wrong, or does the 'pass by reference' not make it through the array_walk process? Cheers -- Phil Driscoll Dial Solutions +44 (0)113 294 5112 http://www.dialsolutions.com http://www.dtonline.org

« previous php.version4 (#12668) next »