Re: cvs: php-src /tests/lang foreach_with_references_001.phpt

From: Date: Thu, 24 Jul 2003 19:44:38 +0000
Subject: Re: cvs: php-src /tests/lang foreach_with_references_001.phpt
References: 1  Groups: php.cvs 
Request: Send a blank email to php-cvs+get-22789@lists.php.net to get a copy of this message
Hello Zeev, Thursday, July 24, 2003, 3:21:54 PM, you wrote: ZS> zeev Thu Jul 24 09:21:54 2003 EDT ZS> Added files: ZS> /php-src/tests/lang foreach_with_references_001.phpt ZS> Log: ZS> Add foreach() test with references ZS> Index: php-src/tests/lang/foreach_with_references_001.phpt ZS> +++ php-src/tests/lang/foreach_with_references_001.phpt ZS> --TEST-- ZS> foreach() with references ZS> --FILE-- ZS> <?php $arr = array(1 =>> "one", 2 => "two", 3 => "three"); ZS> foreach($arr as $key => $val) { ZS> $val = $key; ZS> } ZS> print_r($arr); ZS> foreach($arr as $key => &$val) { ZS> $val = $key; ZS> } ZS> print_r($arr); ZS> --EXPECT-- ZS> Array ZS> ( ZS> [1] => one ZS> [2] => two ZS> [3] => three ZS> ) ZS> Array ZS> ( ZS> [1] => 1 ZS> [2] => 2 ZS> [3] => 3 ZS> ) WOW Coooooool :-) but there is one thing i wonder about: php -r '$ar=array(1=>"a",2=>"b",3=>"c");foreach($ar as $k=>&$v) if ($k==2) unset($v); print_r($ar);' Array ( [1] => a [2] => b [3] => c ) I guess the main question is what should happen? I'd expect the result to be $ar[2] = NULL since obviously you can't unset $ar[2] this way. (I tried this because in SPL you can). Best regards, Marcus mailto:helly@php.net

« previous php.cvs (#22789) next »