QueenZ Posted August 16, 2008 Share Posted August 16, 2008 Hi guys! I don't know why but this php code outputs me the array wrong... <?php $options = array ( 01 => 'adam', 02 => 'betty', 03 => 'charles', 04 => 'denise', 05 => 'eric', 06 => 'adam', 07 => 'betty', 08 => 'charles', 09 => 'denise', 10 => 'eric' ); foreach ($options as $index => $value) { echo $index . "<br>"; } ?> It outputs... 1 2 3 4 5 6 7 0 10 But why?? What does it mean?? First of all there are 9 numbers not 10 and second of all it shows 0 after 7 not 8 and 9 is missing as well..? What have i made wrong?? Please help!! Link to comment https://forums.phpfreaks.com/topic/119999-php-array-output/ Share on other sites More sharing options...
ignace Posted August 16, 2008 Share Posted August 16, 2008 remove the zero before the numbers $options = array ( 1 => 'adam', 2 => 'betty', 3 => 'charles', 4 => 'denise', 5 => 'eric', 6 => 'adam', 7 => 'betty', 8 => 'charles', 9 => 'denise', 10 => 'eric' ); Link to comment https://forums.phpfreaks.com/topic/119999-php-array-output/#findComment-618133 Share on other sites More sharing options...
wildteen88 Posted August 16, 2008 Share Posted August 16, 2008 But why?? What does it mean?? First of all there are 9 numbers not 10 and second of all it shows 0 after 7 not 8 and 9 is missing as well..? What have i made wrong?? Please help!! When you start numbers with a 0, PHP thinks you mean octal notation. Link to comment https://forums.phpfreaks.com/topic/119999-php-array-output/#findComment-618137 Share on other sites More sharing options...
QueenZ Posted August 16, 2008 Author Share Posted August 16, 2008 yes it worked when i removed zero oh, never mind.. Link to comment https://forums.phpfreaks.com/topic/119999-php-array-output/#findComment-618139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.