php4-beta | 200004
Date: 04/12/00
- Next message: Cynic: "Re: [PHP4BETA] Looking for PHP on win32 information..."
- Previous message: Mike Robinson: "RE: [PHP4BETA] cat /etc/passwd"
- In reply to: Wasim Juned: "[PHP4BETA] array_walk behaving oddly ..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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. *
-- PHP 4.0 Beta Mailing List <http://www.php.net/version4/> To unsubscribe, e-mail: php4beta-unsubscribe <email protected> For additional commands, e-mail: php4beta-help <email protected> To contact the list administrators, e-mail: php4beta-admin <email protected>
- Next message: Cynic: "Re: [PHP4BETA] Looking for PHP on win32 information..."
- Previous message: Mike Robinson: "RE: [PHP4BETA] cat /etc/passwd"
- In reply to: Wasim Juned: "[PHP4BETA] array_walk behaving oddly ..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

