Jump to content

PHP Switch Statement


Mateobus

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.