Jump to content

Recommended Posts

if ($_SERVER['PHP_SELF'] == '/pmi.php' OR $_SERVER['PHP_SELF'] == '/pmsent.php'){
			$location = 'Using Messenger';
			}else{
			$location  = '';
			}

 

I wanted to use

 

if ($_SERVER['PHP_SELF'] == '/pmi.php' OR '/pmsent.php'){
			$location = 'Using Messenger';
			}else{
			$location  = '';
			}

 

But that doesn't work, I need to check pmi.php, pmsent.php and pms.php, but I don't want to use if $_SERVER['PHP_SELF'] == BLA OR $_SERVER['php_selft'] again.. blah

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/
Share on other sites

I think there is no other way. May be you could use shorter variable name instead of  $_SERVER['PHP_SELF'] like

$ps = $_SERVER['PHP_SELF'];

$ps = $_SERVER['PHP_SELF'];
if ($ps == '/pmi.php' || $ps == '/pmsent.php'||...)

 

What's the difference between || and OR ?

What's the difference between || and OR ?

 

Their precedence values.  In your particular  usage they both have the same end result.

 

If you have a list of values to check against a variable using an OR condition, you can use in_array as a cleaner method of doing it.  I find it doesn't really matter much until your at 3 or more values though.

 

$values = array('/pmi.php', '/pmsent.php');
if (in_array($_SERVER['PHP_SELF'], $values)){ 
  ...
}

 

 

What's the difference between || and OR ?

 

Their precedence values.  In your particular  usage they both have the same end result.

 

If you have a list of values to check against a variable using an OR condition, you can use in_array as a cleaner method of doing it.  I find it doesn't really matter much until your at 3 or more values though.

 

$values = array('/pmi.php', '/pmsent.php');
if (in_array($_SERVER['PHP_SELF'], $values)){ 
  ...
}

 

Lol! At 3 more values? :(

 

Speed wise, what do you suggest? the old fashion

 

if ($_SERVER['PHP_SELF'] == '/pmi.php' OR $_SERVER['PHP_SELF'] == '/pmsent.php'){
			$location = 'Using Messenger';
			}else{
			$location  = '';
			}

 

or

 

$values = array('/pmi.php', '/pmsent.php');
if (in_array($_SERVER['PHP_SELF'], $values)){ 
  ...
}

 

Speed wise is there any noticeable difference? This will be run with each refresh for each user on my forum.

I doubt one over the other would make any noticeable difference in speed.  It's mainly a readability thing.  You can certainly use in_array for just two values if you want.  the three or more is just kind of my personal rule as I find that is when it makes the most difference readability wise (exact number varies some on the length of the values).

 

I doubt one over the other would make any noticeable difference in speed.  It's mainly a readability thing.  You can certainly use in_array for just two values if you want.  the three or more is just kind of my personal rule as I find that is when it makes the most difference readability wise (exact number varies some on the length of the values).

 

Topic Solved

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.