Re: [PHP4BETA] problem passing arrays by reference using array_walk
| From: | Phil Driscoll | Date: | Mon, 27 Mar 2000 15:28:27 +0000 |
| Subject: | Re: [PHP4BETA] problem passing arrays by reference using array_walk | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-12673@lists.php.net to get a copy of this message | ||
Andrei wrote:
>How come you are not using $Item in SetArray()? That's the current item
>that you are supposed to work on. $Array2 is just userdata.
Because Array2 is not the array I am walking. Bear in mind that the example
I posted was a simple example to illustrate the problem. In reality, I want
to do something much more complex to items in Array2 depending on what
happens as I walk through Array1, but I need it to happen to the real
Array2, not a local copy of it.
Cheers
--
Phil Driscoll
Dial Solutions
+44 (0)113 294 5112
http://www.dialsolutions.com
http://www.dtonline.org
-----Original Message-----
From: Andrei Zmievski <andrei@ispi.net>
To: Phil Driscoll <phil@dialsolutions.co.uk>
Cc: php4beta <php4beta@lists.php.net>
Date: Monday, March 27, 2000 3:38 PM
Subject: Re: [PHP4BETA] problem passing arrays by reference using array_walk
>On Mon, 27 Mar 2000, Phil Driscoll wrote:
>> 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?
>
>
>-Andrei
>* I don't mind going nowhere as long as it's an interesting path. *