vendredi 27 mai 2016

How to highlight current link in foreach loop

I have a script that lists all the directories as links.

<?php
$dirs = array_filter(glob('../*'), 'is_dir');
?>

<ul style="float:left;">
<?php
foreach ($dirs as $nav) {
    echo "<li><a href='$nav'>".basename($nav)."</a></li>";
}
?>
</ul>

I want to highlight the current directory, or give the current link a class or id. I understand that i need if statement to accomplish this like if(currentLink=thisLink) { // add span class somehow} else {// continue looping} , but I am not completely sure how to do this.

What would be the correct way to implement this ?

Aucun commentaire:

Enregistrer un commentaire