MetalSmith Posted June 15, 2009 Share Posted June 15, 2009 Hi all, Is there a way to set a variable to a range of values. I need a way to do this: $x = "5" OR "6" OR "7"; This does not work I understand, but I need a way to define a vaiable to a range of numbers. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/162273-variables-with-multipal-values/ Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 An array? Quote Link to comment https://forums.phpfreaks.com/topic/162273-variables-with-multipal-values/#findComment-856489 Share on other sites More sharing options...
Philip Posted June 15, 2009 Share Posted June 15, 2009 To extend Maq's reply: range() Quote Link to comment https://forums.phpfreaks.com/topic/162273-variables-with-multipal-values/#findComment-856491 Share on other sites More sharing options...
Maq Posted June 15, 2009 Share Posted June 15, 2009 To extend Maq's reply: range() Yes that will work, but not sure how variant your numbers will be. You can just check to see if a value is in the array, for example: $arr = array(1,2,3); if(in_array(1, $arr)) { echo "true"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162273-variables-with-multipal-values/#findComment-856493 Share on other sites More sharing options...
MetalSmith Posted June 15, 2009 Author Share Posted June 15, 2009 Thanks for the help!!! That was easy!! Quote Link to comment https://forums.phpfreaks.com/topic/162273-variables-with-multipal-values/#findComment-856496 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.