samedi 23 janvier 2016

If condition that loops through an array

I have an array which has several keys, each may be true/false:

$hide[1] = false; 
$hide[2] = false; 
$hide[3] = true;

I want a <div> block to appear in my HTML if at least one key is set to true:

<?php if ($some_condition_here==true) { ?> 
<div>show me if at least one value is "true"</div>
<?php } else { } ?>

What is the best practice to do this, considering that sometimes I don't know in advance how many keys I may have (in this example, 3, though might be more). I can assume that max number will be about 20 though.

I'm not sure how to do this, since I don't know how to use loop with if, and also it needs to stop checking on the first event it finds a true.

Aucun commentaire:

Enregistrer un commentaire