普通陣列- $fruits = array("apple", "banana", "cherry");
- $fruits = ["apple", "banana", "cherry"];
- echo $fruits[0];
複製代碼 關聯陣列(類似於map)- $person = array("first_name" => "John", "last_name" => "Doe", "age" => 30);
- $person = ["first_name" => "John", "last_name" => "Doe", "age" => 30];
- echo $person["first_name"];
複製代碼 二維陣列- $students = array(
- array("name" => "Alice", "grade" => 90),
- array("name" => "Bob", "grade" => 85),
- array("name" => "Charlie", "grade" => 88)
- );
- echo $students[0]["name"];
- echo $students[1]["grade"];
複製代碼 |