Jump to content

How to rewrite this ( if and if )


manalnor

Recommended Posts

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

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";}

 

 

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

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.