note 30013 added to function.array-shift

From: Date: Tue, 04 Mar 2003 08:11:51 +0000
Subject: note 30013 added to function.array-shift
Groups: php.notes 
Request: Send a blank email to php-notes+get-44814@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: $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://www.php.net/manual/en/function.array-shift.php http://master.php.net/manage/user-notes.php?action=edit+30013 http://master.php.net/manage/user-notes.php?action=delete+30013 http://master.php.net/manage/user-notes.php?action=reject+30013

« previous php.notes (#44814) next »