note 64340 deleted from control-structures.foreach by bjori

From: Date: Wed, 12 Apr 2006 18:17:53 +0000
Subject: note 64340 deleted from control-structures.foreach by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-107907@lists.php.net to get a copy of this message
Note Submitter: watt dot john dot runyon at gmail dot com Reason: in docs ---- 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

« previous php.notes (#107907) next »