|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-08-03 15:53 UTC] requinix@php.net
-Status: Open
+Status: Not a bug
-Package: Unknown/Other Function
+Package: Scripting Engine problem
[2016-08-03 15:53 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 09:00:02 2026 UTC |
Description: ------------ Hello, this is a pretty basic issue, basically, it seems that when using an array with a mix of strings and integers or default keys (0, 1, 2 etc), if using foreach to iterate through each element of the array intending for something specific to happen when the string key is hit, and having a 0 element in the array, the 0 element is running what should only be happening when that string element is in the array. I do not believe this issue had occurred in previous versions of php but I had just recently updated to 5.6.24 from 5.6.21. Thank you, Test script: --------------- <?php // Test for switch not running default code when array element key is 0 if there is a mix of array keys that are numerical along with a string array key $test = array(0 => "First element, should be 0",1 => "Second element, should be 1",2 => "Third element, should be 2","Three" => "Fourth element, should be Three"); print_r($test); foreach($test as $k => $v) { switch($k) { case "Three": echo "not to be printed\n"; break; default: echo $k.": ".$v."\n"; break; } } ?> Expected result: ---------------- Array ( [0] => First element, should be 0 [1] => Second element, should be 1 [2] => Third element, should be 2 [Three] => Fourth element, should be Three ) 0: First element, should be 0 1: Second element, should be 1 2: Third element, should be 2 not to be printed Actual result: -------------- Array ( [0] => First element, should be 0 [1] => Second element, should be 1 [2] => Third element, should be 2 [Three] => Fourth element, should be Three ) not to be printed 1: Second element, should be 1 2: Third element, should be 2 not to be printed