poe Posted April 16, 2008 Share Posted April 16, 2008 is there a way to have case greater than a number like: i am looping through a baseball boxscore, which i put into an array arrBox: Array ( [0] => final~2~3~4~5~6~7~8~9~10~r~h~e [1] => toronto~1~0~1~0~1~1~0~0~1~5~10~1 [2] => texas~0~0~1~1~1~0~0~0~0~4~10~0 ) foreach($arrBox as $k=>$v) { $box[] = split("~", $v); } $boxhead[] = array_shift($box); foreach($boxhead[0] as $k=>$inng) { switch($inng) { case '>9': // greather than 9 = xtra innings $boxExtra = 'extra innings'; break; case 'r': $boxScore = $box[0][$k] .'-'. $box[1][$k]; break; } } echo $boxScore .' '. $boxExtra; is there a way to have case greater than a number like: case '>9': it seems to be looking for literlly '>' and 9... thanks chris Link to comment https://forums.phpfreaks.com/topic/101396-switch-case/ Share on other sites More sharing options...
p2grace Posted April 16, 2008 Share Posted April 16, 2008 Why does it need to be a switch? Why not an if statement? Link to comment https://forums.phpfreaks.com/topic/101396-switch-case/#findComment-518601 Share on other sites More sharing options...
poe Posted April 16, 2008 Author Share Posted April 16, 2008 good point.. i didnt have a real reason why, i just tried it and i didnt work, so i thought i would ask the Q just to see if it could be done.. thanks Link to comment https://forums.phpfreaks.com/topic/101396-switch-case/#findComment-518605 Share on other sites More sharing options...
kenrbnsn Posted April 16, 2008 Share Posted April 16, 2008 Yes, you can use conditionals in the case statement, but you need to switch on the value "true": <?php switch(true) { case ($inng > 9): // greather than 9 = xtra innings $boxExtra = 'extra innings'; break; case ($inng == 'r'): $boxScore = $box[0][$k] .'-'. $box[1][$k]; break; } ?> Ken Link to comment https://forums.phpfreaks.com/topic/101396-switch-case/#findComment-518708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.