1

i have month array like

$month = array(
    01 => "January",
    02 => "February",
    03 => "March",
    04 => "April",
    05 => "May",
    06 => "June",
    07 => "July",
    08 => "August",
    09 => "September",
    10 => "October",
    11 => "Novemeber",
    12 => "December"
);

but when i print_r this it display like this

Array
(
    [1] => January
    [2] => February
    [3] => March
    [4] => April
    [5] => May
    [6] => June
    [7] => July
    [0] => September
    [10] => October
    [11] => Novemeber
    [12] => December
)

it displaying sept as 0 and the month of august is not dispalying.

can any one please tell me what is the problem with this.
Thanks

0

2 Answers 2

4

Try adding quotes:


$month = array(
    "01" => "January",
    "02" => "February",
    "03" => "March",
    "04" => "April",
    "05" => "May",
    "06" => "June",
    "07" => "July",
    "08" => "August",
    "09" => "September",
    "10" => "October",
    "11" => "Novemeber",
    "12" => "December"
);
Sign up to request clarification or add additional context in comments.

Comments

1

Nubmber starting from 0 are interpreted as octal constats.

Since 8 and 9 are not a valid digits in octal, 08 and 09 are invalid numbers and both interpreted as just 0. "08" is string and even in case of arithmetical operations, will be interpreted as normal decimal integer:

"echo '08'+'08'; // 16

Hence using strings should be safe for your case.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.