PHP syntax: iterate over an associative array

Contributor Icon Contributed by qmchenry  
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
";

 

No Comments -


No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment -