Board logo

標題: PHP 基礎語法(三) 陣列 [打印本頁]

作者: 陳育霖    時間: 2023-9-7 21:34     標題: 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"];
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/) Powered by Discuz! 7.2