返回列表 發帖

PHP 基礎語法(三) 陣列

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

返回列表