SharkBait Posted October 5, 2006 Share Posted October 5, 2006 If I need toa large range of values in a switch what is the best way?[code]<?php$value = 192;switch($value) { case 1 to 400: // Do something break; case 401 to 601: // Do something else break;}?>[/code]Its similar to VB.NET with 1 to 400, not sure if PHP can do the same thing. Quote Link to comment Share on other sites More sharing options...
brendandonhue Posted October 5, 2006 Share Posted October 5, 2006 [code=php:0]<?php$value = 192;if($value >= 1 && $value <= 400){ // Do something} elseif($value >= 401 && $value <= 601){ // Do something else}?>[/code] Quote Link to comment Share on other sites More sharing options...
alpine Posted October 5, 2006 Share Posted October 5, 2006 [code]<?php$value = 192;switch(true){case in_array($value, range(1,400)): echo "between 1-400"; break;case in_array($value, range(401,601)): echo "between 401-601"; break;}?>[/code] Quote Link to comment Share on other sites More sharing options...
SharkBait Posted October 5, 2006 Author Share Posted October 5, 2006 Ah both of those make sense. I forgot I could do comparisons in the cases.Thanks :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.