dumpty Posted August 25, 2007 Share Posted August 25, 2007 Hey I'm creating a calendar type thing. The variable $month will be a value ranging from 1-12. I need somehow to translate 1, the first month, in january - 2 into february - 3 into march etc. It auto increases so i cant just change the value to jan, feb. $month has to server two purposes and i dont know how to get it to turn "1" into "january". Any ideas? Could somebody please give me some code for it or even a pointer? Its quite important! Thanks Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2007 Share Posted August 25, 2007 make an array $months = array(1=>'January', 2=>'February...); Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 25, 2007 Share Posted August 25, 2007 a case may be a wise option Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2007 Share Posted August 25, 2007 Making a switch statement is a lot more code than an array Quote Link to comment Share on other sites More sharing options...
SirChick Posted August 25, 2007 Share Posted August 25, 2007 true. Quote Link to comment Share on other sites More sharing options...
dumpty Posted August 25, 2007 Author Share Posted August 25, 2007 Hey I need it to still remain its original value if that makes sense. So i need $month to still be usable as an integer and as a month. Like "Month X is Y" were X=1 and Y=January. Sorry if im not making myself clear :/ Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 25, 2007 Share Posted August 25, 2007 So when you need to print "January" you use $months[$month]; When you want 1, you use $month; Quote Link to comment Share on other sites More sharing options...
cgm225 Posted August 25, 2007 Share Posted August 25, 2007 This is not urgent to me.. please read:: http://www.phpfreaks.com/forums/index.php/topic,6264.0.html Quote Link to comment Share on other sites More sharing options...
Barand Posted August 25, 2007 Share Posted August 25, 2007 you don't need an array <?php $month = 3; $monthname = date('F', mktime(0,0,0,$month)); echo $monthname; // March ?> for convenince, make it a function <?php function mn($m) { return date('F', mktime(0,0,0,$m)); } $month = 3; echo mn($month); // March ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.