karimali831 Posted July 28, 2010 Share Posted July 28, 2010 Hi Ok, so I pick a random value 23 for example and I want this value to be in between two other values. E.g. if 23 is in between 20 and 30, then continue otherwise die. How can I do this? Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/ Share on other sites More sharing options...
Alex Posted July 28, 2010 Share Posted July 28, 2010 What would the range of the random value being picked be? You can use rand to pick random numbers. Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1092077 Share on other sites More sharing options...
karimali831 Posted July 28, 2010 Author Share Posted July 28, 2010 This for example: $userscoreratio($userID) = 23% $ds['ratio_low'] = 20% $ds['ratio_high'] = 30% if($userscoreratio($userID) >= $ds['ratio_low'] && =< $ds['ratio_high']) Is this the correct if statement for what I want to achieve? Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1092078 Share on other sites More sharing options...
Alex Posted July 28, 2010 Share Posted July 28, 2010 There are some problems with that. I think you want something like this: $lower = 20; $higher = 30; $var = 23; if($var >= $lower && $var <= $higher) { // ... } Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1092082 Share on other sites More sharing options...
karimali831 Posted July 28, 2010 Author Share Posted July 28, 2010 Ok, so this IF statement if(($ds['ratio_low'] || $ds['ratio_high']) && userscoreratio($userID) >= $ds['ratio_low'] && userscoreratio($userID) <= $ds['ratio_low']) Means if $ds['ratio_low'] or $ds['ratio_high'] is not 0 and userscoreratio (23%) is greater or equal to $ds['ratio_low'] (20%) AND userscoreratio (23%) is equal or lesser than $ds['ratio_high'] (30%) ?? Thanks for help. Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1092087 Share on other sites More sharing options...
Alex Posted July 28, 2010 Share Posted July 28, 2010 Yes, but don't you want it to be less than or equal to $ds['ratio_high']? Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1092092 Share on other sites More sharing options...
karimali831 Posted July 28, 2010 Author Share Posted July 28, 2010 Yeah, I changed my post before your reply. -- Thanks. Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1092096 Share on other sites More sharing options...
karimali831 Posted July 30, 2010 Author Share Posted July 30, 2010 Something that did not work for me, not sure why: elseif(($ds['ratio_low'] || $ds['ratio_high']) && clanscoreratio($clanID) < $ds['ratio_low'] || clanscoreratio($clanID) > $ds['ratio_high']) I had to use elseif(($ds['ratio_low'] || $ds['ratio_high']) AND clanscoreratio($clanID) < $ds['ratio_low'] || clanscoreratio($clanID) > $ds['ratio_high']) I thought "AND" and "&&" operate exackly the same? why doesn't "&& clanscoreratio..." work and "AND clanscoreratio.." does work? Link to comment https://forums.phpfreaks.com/topic/209102-help-with-php-operator/#findComment-1093227 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.