PHP中的陣列分為三種類型,分別是索引數組,關聯數組和多維數組,接下來就帶大家一起來看看這三種數組。
1.索引陣列 - 有數字索引的陣列
<?php $cars=array("nihao","shijie","Vhehe"); var_dump($cars); ?>
輸出:
array(3) { [0]=> string(5) "nihao" [1]=> string(6) "shijie" [2]=> string(5) "Vhehe" }
#2.關聯陣列 - 帶有指定鍵的陣列
<?php $age=array("a"=>"35","b"=>"37","c"=>"43"); var_dump($age); ?>
輸出:
array(3) { ["a"]=> string(2) "35" ["b"]=> string(2) "37" ["c"]=> string(2) "43" }
#3.多維陣列 -包含一個或多個陣列的陣列
<?php $fruits = array ( "fruits" => array("a" => "orange", "b" => "banana", "c" => "apple"), "numbers" => array(1, 2, 3, 4, 5, 6), "holes" => array("first", 5 => "second", "third") ); ?>
輸出:
array(3) { ["fruits"]=> array(3) {["a"]=>string(6) "orange" ["b"]=>string(6) "banana" ["c"]=>string(5) "apple" } ["numbers"]=> array(6) { [0]=>int(1) [1]=>int(2) [2]=>int(3) [3]=>int(4) [4]=>int(5) [5]=>int(6) } ["holes"]=> array(3) { [0]=>string(5) "first" [5]=>string(6) "second" [6]=>string(5) "third" } }
建議:《2021年PHP面試題大匯總(收藏)》《php影片教學》
以上是PHP中的array()詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!