-1

For the past two hours I've been on Google trying to solve this before coming to ask for help, I was really hoping I would of been able to solve this, but unfortunately I've hit a brick wall.

This is for a menu item in bootstrap, I'm asking PHP, if $page_title = "Index" is set, the list item will be highlighted, else it won't be highlighted, but all I'm getting at the moment is a blank page, any advice would be much appreciated, thank you.

<li <?php echo isset($page_title == "Index" ? "class='active'" : ""); ?>>
    Index
</li>

Edit: I have the following below in my php file, but the page is still blank.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
Qirel
  • 25,449
  • 7
  • 45
  • 62
Have a Laugh
  • 177
  • 1
  • 9

1 Answers1

2

Your syntax is not entirely correct. The isset() function will return a boolean (true/false), and this cannot be compared against the value of the variable, which is a string.

You should first check if the variable is set, then check its value separately, as shown below.

<li <?php echo isset($page_title) && $page_title == "Index" ? "class='active'" : ""; ?>>
Qirel
  • 25,449
  • 7
  • 45
  • 62