|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-27 21:48 UTC] derick@php.net
-Status: Open
+Status: Not a bug
[2013-01-27 21:48 UTC] derick@php.net
[2013-01-27 22:00 UTC] jessewalker at gmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 09:00:01 2025 UTC |
Description: ------------ I'd set up a multi-dimensional array with the first level having 12 entries 01 to 12 (months), and the second level having 01 to 31 (days) depending on the month. e.g., $months[01][01] = "..."; ... $months[01][31] = "..."; $months[02][01] = "..."; ... $months[02][28] = "..."; ... I found that when iterating through $months with: foreach($months[1] as $day => $entry) and just printing out the $day value, that I'd get results like: 1 .. 7 0 10 .. 31 Notice that 8 and 9 don't print out, but 0 (zero) instead. All other numbers are fine. I tested this all the way up to $months[12] and get the same result, though it fails miserably on $months[8] and $months[9] with the following: PHP Notice: Undefined offset: 8 in /home/pi/php/test.php on line 10 PHP Warning: Invalid argument supplied for foreach() in /home/pi/php/test.php on line 10 Remember that I set my $months array up with 08 and 09 (same as the other numbers having a leading zero). So it's not just an issue at the 2nd level of a multi-dimensional array. With this in mind I reduced my test code down and still get the same issue. It's not only a multi-dimensional array issue, but an array issue affecting entries 8 and 9. The multi-dimensional array gives a slightly different result, so this is why I've mentioned it first. I get the exact same results with: PHP 5.3.6-13ubuntu3.9 with Suhosin-Patch (cli) (built: Sep 12 2012 19:02:11) -- from XBMCbuntu on an HP ProLiant MicroServer N40L PHP 5.6.0-dev (cli) (built: Jan 27 2013 20:37:53) -- from Git master, on the same box I run XBMCbuntu on PHP 5.4.4-11 (cli) (built: Jan 18 2013 02:49:29) -- from Raspbian "Wheezy" 2012-12-16 on a Raspberry Pi All systems fully up to date using apt-get. I ran my tests from the CLI with `php test.php`, and the Git test with `/opt/bin/php test.php`. I know that I could just not set my arrays up with 01..09, and use 1..9 instead - though it's still a quirky issue all the same. Is there any explanation for this, or am I missing something? I'm more than happy to provide full code if requested. The test code provided should be enough to get some idea. Test script: --------------- <?php $num[1] = "One"; $num[01] = "ZeroOne"; $num[02] = "ZeroTwo"; $num[2] = "Two"; $num[8] = "Eight"; $num[08] = "ZeroEight"; $num[09] = "ZeroNine"; $num[9] = "Nine"; print("1: ".$num[1]."\r\n"); print("01: ".$num[01]."\r\n"); print("02: ".$num[02]."\r\n"); print("2: ".$num[2]."\r\n"); print("8: ".$num[8]."\r\n"); print("08: ".$num[08]."\r\n"); print("09: ".$num[09]."\r\n"); print("9: ".$num[9]."\r\n"); ?> Expected result: ---------------- 1: ZeroOne 01: ZeroOne 02: Two 2: Two 8: ZeroEight 08: ZeroEight 09: Nine 9: Nine Actual result: -------------- 1: ZeroOne 01: ZeroOne 02: Two 2: Two 8: Eight 08: ZeroNine 09: ZeroNine 9: Nine