note 44652 modified in ref.strings by aidan

From: Date: Sun, 15 Aug 2004 13:48:04 +0000
Subject: note 44652 modified in ref.strings by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74702@lists.php.net to get a copy of this message
Here's a simpler "simplest" way to toggle through a set of 1..n colors for web backgrounds: <?php $colours = array('#000000', '#808080', '#A0A0A0', '#FFFFFF'); // Get a colour $color = next($colors) or $color = reset($colors); ?> The code doesn't need to know anything about the number of elements being cycled through. That way you won't have to tracking down all the code when changing the number of colors or the color values. --was-- Here's a simpler "simplest" way to toggle through a set of 1..n colors for web backgrounds: $colors = array('#000000', '#808080', '#A0A0A0', '#FFFFFF'); Call this whenever you want the next color: $color = next($colors) or $color = reset($colors); The code doesn't need to know anything about the number of elements being cycled through. That way you won't have to tracking down all the code when changing the number of colors or the color values. There's probably an easier syntax for this, perhaps a tertiary based on next($colors) ? http://php.net/manual/en/ref.strings.php

« previous php.notes (#74702) next »