so if the url in the address bar is not first.php or second.php it should return false and echo " ", but for some odd reason this is returning true and posting class="current"> even if the url is posting http://www.domain.com/fourth.php.
Hi Thank you that's right I forgot about that, I atually ended up using elseif instead, so :
if(myfullpath() == "http://www.domain.com/first.php"){echo "current";} elseif(myfullpath() == "http://www.domain.com/second.php") {
echo "current";}else echo " ";
I wonder which is a better practice or if there is any difference in server resources.
Both, in this case, are the same. As in using A || B it checks A and if true it ignores B. Similarly in ifelse if first IF statement is true it ignores the second.
But from a view of code maintenance its a single if statement thats better.
yea you are right the elseif statements can become hard to figure out after a while and also || is much shorter and easier to troubleshoot. I have changed it all over to || and it works great! thank you so much !
-- single call to the function (small improvement to performance, plus a bit easier to maintain/reuse later on)
-- [expanding from adarshakb] wrap each IF check in it's own parenthesis, then wrap all the IF checks in parenthesis
-- I prefer to to create the empty $class string, then populate it if needed, and echo out the entire string. This way, you don't leave unnecessary empty 'class=""' in your HTML (again, just a small personal preference)
Bookmarks