J. Doe J. Doe - 6 months ago 19
PHP Question

Array not working

I need help with

array()
because it's not working for some reason.

<?php
if(isset($_GET["page"]) && $_GET["page"] == array("i_gebruikers","gebruikerslijst","nieuwegebruiker","ban")) {
?>
<a href="index.php?page=i_gebruikers"><li class="active">Gebruikers</li></a>
<?php } else { ?>
<a href="index.php?page=i_gebruikers"><li>Gebruikers</li></a>
<?php } ?>


As you can see I'm trying to make a button which has the
active
class when you're on a page defined in the array. However it's completely ignoring the array.

Please help me out, it's very much appriciated!

Answer

You are essentially checking if the value of both counts of $_GET are equal to the full array of items, which they are likely not.

if(isset($_GET['page']) && in_array($_GET['page'], array("i_gebruikers","gebruikerslijst","nieuwegebruiker","ban"))) {

}

Should work just fine.

Comments