Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » PHP Undefined index problem
Closed Thread
Old 08-27-2005, 10:54 PM   #1 (permalink)
 
Newb Techie

Join Date: Jul 2005

Posts: 14

StupidRalph

Default PHP Undefined index problem

I am having problems with the code below complaining of the undefined index.
PHP Code:
<?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 Code:
echo $month[08]; 
It will not throwout any errors.

However if I were to use:

PHP Code:
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.
StupidRalph is offline  
Old 08-28-2005, 12:18 AM   #2 (permalink)
 
Super Techie

Join Date: Apr 2004

Posts: 316

BlazingWolf

Default

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 ) You can have date() output the name of the month.
__________________
BlazingWolf
<font color=\'red\'>
<b>
<a href=\'http://www.gaming-forums.org\'>
Gaming-Forums.org
<a/>
</b>
</font>
BlazingWolf is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On