Re: [PHP4BETA] array_walk behaving oddly ...
| From: | Andrei Zmievski | Date: | Wed, 12 Apr 2000 13:01:56 +0000 |
| Subject: | Re: [PHP4BETA] array_walk behaving oddly ... | ||
| References: | 1 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-13445@lists.php.net to get a copy of this message | ||
On Tue, 11 Apr 2000, Wasim Juned wrote:
> query about php3.0.12 vs PHP Version 4.0b4pl1 regards array_walk
> which is not working as expected.
>
> Here's the code:
> <?
> function changeArray($item)
> {
> $item = "This is $item";
> }
>
> $array = array("a","b");
>
> // array_walk functions different in php3/4
> // in php3 this changes each element
> // but in php4 each element is reinitialised.
> array_walk($array,'changeArray');
>
> while($e = current($array))
> {
> echo "$e<BR>\n";
> next($array);
> }
> ?>
In PHP 4 the array entries are not passed by reference by default. You
need to declare your array function like this to get them to change:
function changeArray(&$item)
{
$item = "This is $item";
}
-Andrei
* The best source is the source code. *