note 64456 deleted from control-structures.while by bjori

From: Date: Fri, 14 Apr 2006 17:36:29 +0000
Subject: note 64456 deleted from control-structures.while by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108097@lists.php.net to get a copy of this message
Note Submitter: spamalot at dustyhouse dot kom Reason: in docs ---- It should be noted that While's post from Apr 6 describes a problem better solved by using a 'for' loop. Although while loops are very useful, if you are in need of a incremented or decremented value you will save code by using its compact syntax: <?php $num = '55' //some arbitrary value echo "<select name=test>"; echo "<option></option>"; //this is for a blank default value for($i=0;$i < $num;$i++) { echo "<option>$i</option>"; } echo "</select>"; ?> Additionally the stated $_POST problem can be solved by simply appending $i to the $_POST variable as such: <?php $field = $_POST['field'.$i] ?> This will work for any array, whether or not it is in a loop.

« previous php.notes (#108097) next »