note 92021 added to control-structures.switch

From: Date: Sun, 05 Jul 2009 19:17:08 +0000
Subject: note 92021 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-157945@lists.php.net to get a copy of this message
Am trying to make a calendar with 'previous' and 'next' user links using the output of the following : if(isset($_GET['mth'])){ switch($_GET['mth']){ case "January": $month=01; break; case "February": $month=02; break; case "March": $month=03; break; case "April": $month=04; break; case "May": $month=05; break; case "June": $month=06; break; case "July": $month=07; break; case "August": $month=8; break; /* write '8' and not '08' */ case "September": $month=9; break; /* write '9' and not '09' */ case "October": $month=10; break; case "November": $month=11; break; case "December":$month=12; break; } } Problem is when $_GET['mth'] based on user clicking previous or next reaches case 'August' or 'September', the above switch case starts outputting $month value = '0' (zero) rather than '08' or '09' as the case should be. As a consequence, the function below: cal-days-in-month(0, $month, $year); produces an error and says invalid input. So I echoed the value of $month for case = August or September and surprisingly the output of the above switch case is $ month=0 as long as for August and September there are preceding '0's, i.e. zeroes before 8 and 9 specified in the above switch case statement, i.e. these are written as '08' and '09' and not as '8' or '9'. So when I changed $ month ='08' and $month='09' to $month=9' and $month='9' in the above switch case statement despite using 'm' (which specifies preceding zeroes) and not 'n' for the date function month format, the above switch case outputs $month=8 or 9 and therefore the function: cal-days-in-month(0, $month, $year); works just fine. Can someone explain what might be going on there? This error repeats itself for every year (since I have previous and next for years also) for these two months only as long as the switch case statement above is written with values '08' and '09' - the moment those are changed to '8' and '9' the error is gone. After the change, the entire calendar script works just fine for all years and without any problems for any and all months. Thanks! ---- Server IP: 209.41.74.194 Probable Submitter: 70.221.128.175 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/92021 Del: integrated -- https://master.php.net/note/delete/92021/integrated Del: useless -- https://master.php.net/note/delete/92021/useless Del: bad code -- https://master.php.net/note/delete/92021/bad+code Del: spam -- https://master.php.net/note/delete/92021/spam Del: non-english -- https://master.php.net/note/delete/92021/non-english Del: in docs -- https://master.php.net/note/delete/92021/in+docs Del: other reasons-- https://master.php.net/note/delete/92021 Reject -- https://master.php.net/note/reject/92021 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#157945) next »