I want to concatenate in the middle of an echo to write an if statement, is this possible? Here is what I have.
echo "<li class='".if ($_GET["p"] == "home") { echo "active"; }."'><a href='#'>Home</a> </li>";
I want to concatenate in the middle of an echo to write an if statement, is this possible? Here is what I have.
echo "<li class='".if ($_GET["p"] == "home") { echo "active"; }."'><a href='#'>Home</a> </li>";
Like this, using the ternary operator:
echo "<li class='". (($_GET["p"] == "home") ? "active" : "") . "'><a href='#'>Home</a> </li>";
echo "<li class='".(($_GET["p"] == "home") ? "active" : "")."'><a href='#'>Home</a> </li>";
Do like this:
echo "<li class='".($_GET["p"] == "home" ? 'active' : '') ."'><a href='#'>Home</a> </li>";