Jump to content

php alternating colour menu


ltoto

Recommended Posts

I just created this. It has pages and colours in arrays:

 

$colours = array('#0000FF', '#FF0000');
$pages = array('Home' => 'index.php', 'Contact' => 'contact.php', 'About' => 'about.php', 'News' => 'news.php');
$maxcolours = count($colours);
$i = 0;
foreach($pages as $key => $value){
echo '<a href="'.$value.'" style="color: '.$colours[$i].'">'.$key.'</a><br>';
$i++;
if($i > $maxcolours-1){
	$i = 0;
}
}

Another solution would be:

<?php
$color = '#0000FF';
$pages = array('Home' => 'index.php', 'Contact' => 'contact.php', 'About' => 'about.php', 'News' => 'news.php');
foreach($pages as $key => $value){
echo '<a href="'.$value.'" style="color: '.$color.'">'.$key.'</a><br>';
        $color = ($color == '#0000FF')?'#FF0000':'#0000FF';
}
}?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.