Jump to content

PHP Array Output...


QueenZ

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.