ltoto Posted July 16, 2008 Share Posted July 16, 2008 hi I want to do a dynamic php menu with alternating colours so for example it would be like this Home - blue Contact - red About - Blue News - red Just basically wondering how I would go about doing something like this? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/115040-php-alternating-colour-menu/ Share on other sites More sharing options...
Xurion Posted July 16, 2008 Share Posted July 16, 2008 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; } } Quote Link to comment https://forums.phpfreaks.com/topic/115040-php-alternating-colour-menu/#findComment-591607 Share on other sites More sharing options...
kenrbnsn Posted July 16, 2008 Share Posted July 16, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/115040-php-alternating-colour-menu/#findComment-591615 Share on other sites More sharing options...
Xurion Posted July 16, 2008 Share Posted July 16, 2008 I prefer arrays so the developer can add and take as many colours as they want Quote Link to comment https://forums.phpfreaks.com/topic/115040-php-alternating-colour-menu/#findComment-591619 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.