Foreach Loops

   

Foreach loops allow you to quickly traverse through an array.

 $array = array("name" => "Jet", "occupation" => "Bounty Hunter" );  foreach ($array as $val) {     echo "<P>$val"; } Prints out: <P>Jet <P>Bounty Hunter 

You can also use foreach loops to get the key of the values in the array:

 foreach ($array as $key => $val) {      echo "<P>$key : $val"; } Prints out: <P>name : Jet <P>occupation : Bounty Hunter 

   
Top


Advanced PHP for Web Professionals
Advanced PHP for Web Professionals
ISBN: 0130085391
EAN: 2147483647
Year: 2005
Pages: 92

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net