|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2014-08-27 16:22 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
[2014-08-27 16:22 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 17:00:01 2025 UTC |
Description: ------------ PHP Version 5.5.9-1ubuntu4.1 but am not sure if that maters in this case. one of the foreach takes the value as ref. the other foreach does not. as you can see in the result of the script, the dump of this array after manipulating after the first foreach is correct. but the comparison within the second foreach is wrong. to get that resolved i have to rename one of the $value variables or use the $value variable in the second foreach also as ref. Test script: --------------- $array = array( 'a'=> 'foo', 'b'=> 'foo', 'c'=> 'foo' ); var_dump($array); foreach($array as &$value) { $value = false; } var_dump($array); $array['b'] = true; var_dump($array); foreach($array as $key => $value) { echo $key.' = '.((int)$value).'<br>'; } Expected result: ---------------- array (size=3) 'a' => string 'foo' (length=3) 'b' => string 'foo' (length=3) 'c' => string 'foo' (length=3) array (size=3) 'a' => boolean false 'b' => boolean false 'c' => boolean false array (size=3) 'a' => boolean false 'b' => boolean true 'c' => boolean false a = 0 b = 1 c = 0 Actual result: -------------- array (size=3) 'a' => string 'foo' (length=3) 'b' => string 'foo' (length=3) 'c' => string 'foo' (length=3) array (size=3) 'a' => boolean false 'b' => boolean false 'c' => &boolean false array (size=3) 'a' => boolean false 'b' => boolean true 'c' => &boolean false a = 0 b = 1 c = 1