Web EndMemo

PHP Associate Array


Associate array initialization:
<?PHP
$arr = array("one"=>"Monday","two"=>"Tuesday","three"=>"Wednesday",
"four"=>"Thursday","five"=>"Friday","six"=>"Saturday","seven"=>"Sunday");
?>

Initialize element by element:
<?PHP
$arr = array();
$arr["one"] = "Monday";
$arr["two"] = "Tuesday";
$arr["three"] = "Wednesday";
$arr["four"] = "Thursday";
$arr["five"] = "Friday";
$arr["six"] = "Saturday";
$arr["seven"] = "Sunday";
?>

Iterate through the associate array:
<?PHP
foreach($arr as $num=>$d)
{
    echo "$num, $d\n";
}
?>

Associate array can also be iterated by list()=each():
<?PHP
while (list($key,$value) = each($arr))
{
    echo "$key, $value\n";
}
?>