In my code here, I have a CSS class called “active” which I use if the $_GET[‘page’] == tutorials, php, mysql, etc…
The problem is, even if the ‘page’ variable is not equal to any of these values, the Tutorials button in this case is still active for some reason.
Any ideas why this would be happening?
Am I using the ‘or’ (||) operand incorrectly?
<?php if($_GET['page'] == 'tutorials' || 'php' || 'mysql' || 'html' || 'css' || 'js') { ?>
<li class="active"> <?php } else { ?> <li> <?php } ?>
<a href="index.php?page=tutorials">Tutorials</a>
<ul>
<li><a href="index.php?page=php">PHP</a></li>
<li><a href="index.php?page=mysql">MySQL</a></li>
<li><a href="index.php?page=html">HTML</a></li>
<li><a href="index.php?page=css">CSS</a></li>
<li><a href="index.php?page=js">JS</a></li>
</ul>
</li>
You are using
||incorrectly.You would need to test each whole condition separately to use it that way. So you could do:
Here’s an alternate syntax:
Read more about PHP Control Structures, arrays, and
in_array()