1. 程式人生 > >PHP foreach遍歷關聯陣列

PHP foreach遍歷關聯陣列

<?php
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
 
foreach($age as $x=>$x_value)
{
    echo "Key=" . $x . ", Value=" . $x_value;
    echo "<br>";
}
?>
結果:
Key=Peter, Value=35
Key=Ben, Value=37

Key=Joe, Value=43

將json轉化為關聯陣列,通過foreach迴圈遍歷輸出