note 88051 modified in control-structures.for by danbrown

From: Date: Thu, 08 Jan 2009 15:37:49 +0000
Subject: note 88051 modified in control-structures.for by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148952@lists.php.net to get a copy of this message
Just a note on looping through an array using the for() loop. with the array... <?php $array = array("value1","value2","value3"); ?> then... <?php for(reset($array),current($array),next($array){ echo("Element ".key($array)." contains ".current($array)."<br/>"; } ?> is the equivalent of... <?php for($i=0;$i<count($array);$i++){ echo("Element $i contains $array[$i]<br/>"); } ?> I don't know if there is any advantage, just thought I would mention it. --was-- Just a note on looping through an array using the for() loop. with the array... $array = array("value1","value2","value3"); then... for(reset($array),current($array),next($array){ echo("Element ".key($array)." contains ".current($array)."<br/>"; } is the equivalent of... for($i=0;$i<count($array);$i++){ echo("Element $i contains $array[$i]<br/>"); } I don't know if there is any advantage, just thought I would mention it. http://php.net/manual/en/control-structures.for.php

« previous php.notes (#148952) next »