manalnor Posted September 27, 2010 Share Posted September 27, 2010 hello friends, that would help me alot , if i've 2 code all are of if and else code 1 $r = $_SERVER['HTTP_REFERER'];if (stripos($r, $refere) !== false) {echo "good";}else{echo "bad";} code 2 if($line[hits] >= $limited){echo "bad";}else{echo "good";} both are 2 codes where the user should pass before it show good how then it be 1 code not 2 ( if x if y else y2 else x2 ) it like double sandwich Link to comment https://forums.phpfreaks.com/topic/214554-how-to-rewrite-this-if-and-if/ Share on other sites More sharing options...
AbraCadaver Posted September 27, 2010 Share Posted September 27, 2010 This: if (stripos($r, $refere) !== false && $line['hits'] < $limited) {echo "good";}else{echo "bad";} Or this: if (stripos($r, $refere) === false || $line['hits'] >= $limited) {echo "bad";}else{echo "good";} Link to comment https://forums.phpfreaks.com/topic/214554-how-to-rewrite-this-if-and-if/#findComment-1116463 Share on other sites More sharing options...
rwwd Posted September 27, 2010 Share Posted September 27, 2010 if (stripos($r, $refere) !== false) { Careful with the use of !== this can produce unexpected results... It's a lot easier to use != unless your certain that the evaluated items are of the same type (int, char, string, object) Other than that, not sure what your trying to achieve. From abracadaver's suggestion:- if ((stripos($r, $refere) === false) || ($line['hits'] >= $limited)) { Just parenthesize the evaluated parts of either side of the conditional || just because it's easier to read.. Rw Link to comment https://forums.phpfreaks.com/topic/214554-how-to-rewrite-this-if-and-if/#findComment-1116465 Share on other sites More sharing options...
AbraCadaver Posted September 27, 2010 Share Posted September 27, 2010 if (stripos($r, $refere) !== false) { Careful with the use of !== this can produce unexpected results... It's a lot easier to use != unless your certain that the evaluated items are of the same type (int, char, string, object) Other than that, not sure what your trying to achieve. Rw The intent is to see if a string is found in another string by returning the position of the match or false if no match. If the string is found in the other string at position 0 then using 0 != false will evaluate to false, whereas 0 !== false evaluates to true. Link to comment https://forums.phpfreaks.com/topic/214554-how-to-rewrite-this-if-and-if/#findComment-1116470 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.