note 64456 added to control-structures.while
| From: | spamalotatdustyhousedotkom at osu1 dot php dot net | Date: | Fri, 14 Apr 2006 16:32:30 +0000 |
| Subject: | note 64456 added to control-structures.while | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-108092@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 64.71.164.2
Probable Submitter: 209.248.150.2
----
X-Spam-Status: No, hits=4.0 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_20_30,HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/control-structures.while.php
Edit -- http://master.php.net/note/edit/64456
Del: integrated -- http://master.php.net/note/delete/64456/integrated
Del: useless -- http://master.php.net/note/delete/64456/useless
Del: bad code -- http://master.php.net/note/delete/64456/bad+code
Del: spam -- http://master.php.net/note/delete/64456/spam
Del: non-english -- http://master.php.net/note/delete/64456/non-english
Del: in docs -- http://master.php.net/note/delete/64456/in+docs
Del: other reasons-- http://master.php.net/note/delete/64456
Reject -- http://master.php.net/note/reject/64456
Search -- http://master.php.net/manage/user-notes.php