[PHP-CVS] cvs: php-src /tests/lang foreach_with_references_001.phpt

2003-07-24 Thread Zeev Suraski
zeevThu Jul 24 09:21:54 2003 EDT

  Added files: 
/php-src/tests/lang foreach_with_references_001.phpt 
  Log:
  Add foreach() test with references
  
  

Index: php-src/tests/lang/foreach_with_references_001.phpt
+++ php-src/tests/lang/foreach_with_references_001.phpt
--TEST--
foreach() with references
--FILE--
?php

$arr = array(1 = one, 2 = two, 3 = three);

foreach($arr as $key = $val) {
$val = $key;
}

print_r($arr);

foreach($arr as $key = $val) {
$val = $key;
}

print_r($arr);

--EXPECT--
Array
(
[1] = one
[2] = two
[3] = three
)
Array
(
[1] = 1
[2] = 2
[3] = 3
)



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] cvs: php-src /tests/lang foreach_with_references_001.phpt

2003-07-24 Thread Marcus Börger
Hello Zeev,

Thursday, July 24, 2003, 3:21:54 PM, you wrote:

ZS zeevThu 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 Coool :-)

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,
 Marcusmailto:[EMAIL PROTECTED]


-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php