grahamb314 Posted October 18, 2008 Share Posted October 18, 2008 does anyone know how to do an if like this? I have a number range ,say 1-6, now how do i say if the variable int is in this range... do soemthing?? thanks! Link to comment https://forums.phpfreaks.com/topic/128964-solved-if-between-int/ Share on other sites More sharing options...
JasonLewis Posted October 18, 2008 Share Posted October 18, 2008 $i = 4; if($i > 0 && $i < 7){ //do something } OR $i = 4; if($i => 1 && $i <= 6){ //do something } Link to comment https://forums.phpfreaks.com/topic/128964-solved-if-between-int/#findComment-668592 Share on other sites More sharing options...
thebadbad Posted October 18, 2008 Share Posted October 18, 2008 Another method using in_array() and range(): <?php $i = 4; if (in_array($i, range(1, 6))) { //do something } ?> But the other way is probably faster. Link to comment https://forums.phpfreaks.com/topic/128964-solved-if-between-int/#findComment-668595 Share on other sites More sharing options...
grahamb314 Posted October 18, 2008 Author Share Posted October 18, 2008 Thanks for your help, i`ll use the faster one :-) Link to comment https://forums.phpfreaks.com/topic/128964-solved-if-between-int/#findComment-668596 Share on other sites More sharing options...
ghostdog74 Posted October 18, 2008 Share Posted October 18, 2008 if ( array_key_exists("4",range(0,7) )){ echo "yes"; } Link to comment https://forums.phpfreaks.com/topic/128964-solved-if-between-int/#findComment-668597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.