By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,483 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,483 IT Pros & Developers. It's quick & easy.

Function on the months

P: 1
Expand|Select|Wrap|Line Numbers
  1. function month_name($monthNumber) 
  2. {
  3.     $months = array(
  4.     1 =>'January',
  5.     2 =>'February',
  6.     3 =>'March',
  7.     4 =>'April',
  8.     5 =>'May',
  9.     6 =>'June',
  10.     7 =>'July',
  11.     8 =>'August',
  12.     9 =>'Semtember',
  13.     10 =>'October',
  14.     11 =>'Novmeber',
  15.     12 =>'December'
  16.     );
  17.     return $months[$monthnumber];
  18. }
  19.  
  20. for ($Month = 1; $count <= 12; $count++)
  21. {
  22.     $monthName = month_name($count);
  23.  
  24.  
  25.     print_r("Month Number = $count and month Name =     
  26.  
  27. $monthName"<P>);
  28. }

I just don't seem to understanf why this code I made isn't giving me the months name, This is what it is giving me:

Month Number = and month Name =

Month Number = 1 and month Name =

Month Number = 2 and month Name =

Month Number = 3 and month Name =

Month Number = 4 and month Name =

Month Number = 5 and month Name =

Month Number = 6 and month Name =

Month Number = 7 and month Name =

Month Number = 8 and month Name =

Month Number = 9 and month Name =

Month Number = 10 and month Name =

Month Number = 11 and month Name =

Month Number = 12 and month Name =

If you could explain it I would be most grateful.
Jan 28 '09 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
that's because $monthNumber and $monthnumber are two different variables. when I tried your code, I got PHP spitting out a lot of notices telling that.

further, check the variables in the for loop, there's an error, too. and print_r() is meant to print arrays, in your case better use
Expand|Select|Wrap|Line Numbers
  1. echo "Month Number = ", $count, " and month Name = ", $monthName;
regards
Jan 28 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.