For each key and value pair from associative array in PHP

Description

The following code shows how to for each key and value pair from associative array.

Example


<?php// w  w w.ja  va  2s. co m

$links = array("Apache Web Server" => "www.apache.org",
               "Tutorial" => "www.java2s.com",
               "The PHP Scripting Language" => "www.php.net");


foreach($links as $title => $link) {
    echo "<a href=\"http://$link\">$title</a><br />";
}


?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone