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 Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/ 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...); Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333904 Share on other sites More sharing options...
SirChick Posted August 25, 2007 Share Posted August 25, 2007 a case may be a wise option Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333906 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 Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333908 Share on other sites More sharing options...
SirChick Posted August 25, 2007 Share Posted August 25, 2007 true. Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333909 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 :/ Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333912 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; Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333914 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 Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333917 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 ?> Link to comment https://forums.phpfreaks.com/topic/66646-php-numbers-to-months-urgent-help-please/#findComment-333995 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.