note 64340 added to control-structures.foreach
| From: | watt dot john dot runyon at gmail dot com | Date: | Wed, 12 Apr 2006 18:01:08 +0000 |
| Subject: | note 64340 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107900@lists.php.net to get a copy of this message | ||
A 'for' can be used to simulate a 'foreach' I believe, if there is a numerical
index:
<?php
/* Here's setting up the array */
//make an array
$array=array(1, 2, 3, 4, 5, 6);
/* Now setting up the for */
//count the indices in array
$length=count($array);
//loop through
for ($loop=0, $loop<=$length, $loop++) {
$index=$array[$loop]
//do the contents of the "makeshift foreach" here
}
?>
now $index contains the contents of $array[value_of_loop]
if $loop=0, $index=$array[0]
so, $index = 1 in the above example
----
Server IP: 66.163.161.117
Probable Submitter: 66.166.62.34 (proxied: 127.0.0.1)
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/note/edit/64340
Del: integrated -- http://master.php.net/note/delete/64340/integrated
Del: useless -- http://master.php.net/note/delete/64340/useless
Del: bad code -- http://master.php.net/note/delete/64340/bad+code
Del: spam -- http://master.php.net/note/delete/64340/spam
Del: non-english -- http://master.php.net/note/delete/64340/non-english
Del: in docs -- http://master.php.net/note/delete/64340/in+docs
Del: other reasons-- http://master.php.net/note/delete/64340
Reject -- http://master.php.net/note/reject/64340
Search -- http://master.php.net/manage/user-notes.php