在PHP中,有三种常见的方式来定义数组:
$numbers = array(1, 2, 3, 4, 5);
$person = array("name" => "John", "age" => 25, "country" => "USA");
$students = array(
array("name" => "John", "age" => 20, "country" => "USA"),
array("name" => "Emma", "age" => 22, "country" => "UK"),
array("name" => "Luisa", "age" => 21, "country" => "Spain")
);
此外,还可以使用[]
语法来定义数组:
$fruits = ["apple", "banana", "orange"];
这是PHP 5.4版本及更高版本引入的简洁语法。