Loop Through an Associative Array in PHP

Description

The following code shows how to loop Through an Associative Array.

Example


//  ww  w  .j  a va2 s.c om
<?php
   $age=array("XML"=>"35","HTML"=>"37","CSS"=>"43");

   foreach($age as $x=>$x_value) {
     echo "Key=" . $x . ", Value=" . $x_value;
     echo "<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