note 30013 modified in function.array-shift by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:49:28 +0000 |
| Subject: | note 30013 modified in function.array-shift by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79887@lists.php.net to get a copy of this message | ||
Here's a fun little trick for cycling a set of items in the case where you want to say loop
thorugh a set of styles for a tiled effect:
<?php
$styles = array('style1', 'style2', 'style3', ... 'stylen');
while (haveMoreToPrint())
{
array_push($styles, array_shift($styles));
print('<div class="'.$styles[0].'">Some
content</div>');
}
?>
And since the elements that are being shifted off go onto the end, there is no concern as to how
many or how few styles your have or how many times you are going to cycle through them. No
counters, no nothin.
--was--
Here's a fun little trick for cycling a set of items in the case where you want to say loop
thorugh a set of styles for a tiled effect:
$styles = array('style1', 'style2', 'style3', ... 'stylen');
while (haveMoreToPrint())
{
array_push($styles, array_shift($styles));
print('<div class="'.$styles[0].'">Some
content</div>');
}
And since the elements that are being shifted off go onto the end, there is no concern as to how
many or how few styles your have or how many times you are going to cycle through them. No
counters, no nothin.
http://php.net/manual/en/function.array-shift.php