note 10053 added to array_pad

From: Date: Sun, 10 Dec 2000 09:25:23 +0000
Subject: note 10053 added to array_pad
Groups: php.notes 
Request: Send a blank email to php-notes+get-8592@lists.php.net to get a copy of this message
This is useful when using next() and prev() function in a while loop to traverse an array. For example the following code will only output up to 8. $test[] = "1"; $test[] = "2"; $test[] = "3"; $test[] = "4"; $test[] = "5"; $test[] = "6"; $test[] = "7"; $test[] = "8"; $test[] = "9"; $test[] = "10"; $test[] = " "; $test[] = " "; $test[] = " "; $count = count($test); while($i < $count) { $now = current($test); echo "<p>$now</p>"; next($test); next($test); next($test); prev($test); prev($test); prev($test); $i++; next($test); } But if you use: $test = array_pad($test, 13, " "); you will get all of your output. http://www.php.net/manual/function.array-pad.php

« previous php.notes (#8592) next »