Mateobus Posted September 20, 2006 Share Posted September 20, 2006 I Am getting a syntax error with this code:switch(true){ case ($owp >= .667){ $region_points = $region_points+14; } case (($owp < .667) &&($owp >= .5)){ $region_points = $region_points+12; } case (($owp < .5) &&($owp >= .333)){ $region_points = $region_points+10; } case ($owp < .333){ $region_points = $region_points+8; }}I got this from the php.net docs but i guess you can't do this. What is the code to do this idea? Any help is appreciated. Link to comment https://forums.phpfreaks.com/topic/21341-php-switch-statement/ Share on other sites More sharing options...
trq Posted September 20, 2006 Share Posted September 20, 2006 Your syntax error comes from trying to start integers with a decimal. Try using 0.5 instead of .5 etc etc Link to comment https://forums.phpfreaks.com/topic/21341-php-switch-statement/#findComment-95009 Share on other sites More sharing options...
Mateobus Posted September 20, 2006 Author Share Posted September 20, 2006 Thorpe, I tried that and I am getting the same parse error at the first line of the switch statement. Link to comment https://forums.phpfreaks.com/topic/21341-php-switch-statement/#findComment-95012 Share on other sites More sharing options...
Mateobus Posted September 20, 2006 Author Share Posted September 20, 2006 I think i needed a colon where i had brackets. My bad. Link to comment https://forums.phpfreaks.com/topic/21341-php-switch-statement/#findComment-95014 Share on other sites More sharing options...
trq Posted September 20, 2006 Share Posted September 20, 2006 Sorry, your syntax is pretty whack here. Try...[code=php:0]switch(true){ case ($owp >= 0.667) : $region_points = $region_points+14; break; case (($owp < 0.667) && ($owp >= 0.5)) : $region_points = $region_points+12; break; case (($owp < 0.5) && ($owp >= 0.333)) : $region_points = $region_points+10; break; case ($owp < 0.333) : $region_points = $region_points+8; break;}[/code]Ive never used this method with mutliple choices (ie &&) so... might not work. You really probably should really be using if else ifs here. Link to comment https://forums.phpfreaks.com/topic/21341-php-switch-statement/#findComment-95017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.