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. Link to comment https://forums.phpfreaks.com/topic/23111-switch/ 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] Link to comment https://forums.phpfreaks.com/topic/23111-switch/#findComment-104544 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] Link to comment https://forums.phpfreaks.com/topic/23111-switch/#findComment-104579 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 :) Link to comment https://forums.phpfreaks.com/topic/23111-switch/#findComment-104628 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.