php - if statement, same variable -


i'm checking users current page, , applying .css class correct menu item.

my question is, how can best? currently, have this:

    $currentpage = $_server['php_self'];   if($currentpage == "/prefs.php") $active = "active";   if($currentpage == "/acc.php") $active = "active";   if($currentpage == "/forum.php") $active = "active";  <a href='acc.php' title='sync' aria-hidden='true' class='{$active} tiptip'>  <a href='acc.php' title='sync' aria-hidden='true' class='{$active} tiptip'> <a href='forum.php' title='statistics' aria-hidden='true' class='{$active} tiptip'> 

but add active class anchor elements.

<?php $currentpage = $_server['php_self'];  echo "<a href='prefs.php' title='sync' aria-hidden='true' class='" . ($currentpage == '/prefs.php' ? 'active' : '') . " tiptip'>       <a href='acc.php' title='sync' aria-hidden='true' class='" . ($currentpage == '/acc.php' ? 'active' : '') . " tiptip'>       ..."; 

if don't this, use switch() { case '': break; } setup.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -