PHP Undefined index problem

Status
Not open for further replies.

StupidRalph

Solid State Member
Messages
14
I am having problems with the code below complaining of the undefined index.
PHP:
<?php
//Months in the year

$month[0] = 'January';
$month[01] = 'February';
$month[02] = 'March';
$month[03] = 'April';
$month[04] = 'May';
$month[05] = 'June';
$month[06] = 'July';
$month[07] = 'August';
$month[08] = 'September';
$month[09] = 'October';
$month[10] = 'November';
$month[11] = 'December';

//Current month
$currentMonth = date('m');

echo $month[$currentMonth];
?>

If I were to use:

PHP:
echo $month[08];

It will not throwout any errors.

However if I were to use:

PHP:
echo $month[$currentMonth];

It complains of having an undefined index.

I can echo out the variable $currentMonth have it return 08 since today is in August the eigth month of the year. So I don't see the difference when $currentMonth= 08 and when I manually type in 08 in the array index.
 
Are you sure it date('m') doesn't give your just '8' and not '08'.

And why are you doing that?(If you provide a good asnwer I won't think less of you :p) You can have date() output the name of the month.
 
Status
Not open for further replies.
Back
Top Bottom