<!DOCTYPE html> <html> <head> <title></title> </head> <body> <?php $array = array( "a" => "d", "b" => "o", "c" => "g" ); //印出索引a的值 echo $array["a"] . "<br>"; //走訪Array foreach ($array as $key => $value) { echo "$key " . $value . ","; } echo '<br><br>'; //PHP 5.4之後才可以用 $array = [ "a" => "d", "b" => "o", "c" => "g" ]; //走訪Array foreach ($array as $key => $value) { echo "$key " . $value . ","; } echo '<br><br>'; $array = [ "d", "o", "g" ]; foreach ($array as $key => $value) { echo "$key " . $value . ","; } echo '<br><br>'; //印出陣列 print_r($array); echo '<br><br>'; //將值消除 unset($array[0]); foreach ($array as $key => $value) { echo "$key " . $value . ","; } echo '<br><br>'; $array = array(); $array[] = "d"; $array[] = "o"; $array[] = "g"; foreach ($array as $key => $value) { echo "$key " . $value . ","; } echo '<br><br>'; $array = array( "d", "o", "g", array( "i", "s", array( "w", "h", "o" ) ) ); echo "$array[0]$array[1]$array[2] " . $array[3][0] . $array[3][1] . " " . $array[3][2][0] . $array[3][2][1] . $array[3][2][2]; ?> </body> </html>
結果:
參考資料:
http://www.php.net/manual/en/language.types.php
http://www.php.net/manual/en/language.types.array.php
http://www.php.net/print_r