PHP syntax: iterate over an associative array

Contributor Icon Contributed by qmchenry Date Icon December 27, 2003  
Tag Icon Tagged: PHP programming

An associative array stores an arbitrary index in addition to the values. This is useful for storing configuration information such as in the $_SERVER array.


An individual element of this array can be retrieved with:

$_SERVER['SITE_HTMLROOT']

To loop through all of the elements in $_SERVER and display the values and their corresponding indexes:

foreach ( $_SERVER as $ind=>$val )
echo "$ind : $val
";

Previous recipe | Next recipe |
 
blog comments powered by Disqus