Monkuar Posted March 16, 2012 Share Posted March 16, 2012 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 More sharing options...
darkfreaks Posted March 16, 2012 Share Posted March 16, 2012 have you tried using file_exists to check if it exists or not Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327963 Share on other sites More sharing options...
q11we Posted March 16, 2012 Share Posted March 16, 2012 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'||...) Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327965 Share on other sites More sharing options...
Monkuar Posted March 16, 2012 Author Share Posted March 16, 2012 Quote 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 ? Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327966 Share on other sites More sharing options...
kicken Posted March 16, 2012 Share Posted March 16, 2012 Quote 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)){ ... } Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327970 Share on other sites More sharing options...
Monkuar Posted March 16, 2012 Author Share Posted March 16, 2012 Quote Quote 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. Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327972 Share on other sites More sharing options...
kicken Posted March 16, 2012 Share Posted March 16, 2012 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). Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327974 Share on other sites More sharing options...
Monkuar Posted March 16, 2012 Author Share Posted March 16, 2012 Quote 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 Link to comment https://forums.phpfreaks.com/topic/259039-must-be-a-more-effecient-way/#findComment-1327977 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.