在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版本及更高版本引入的简洁语法。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: getdate函数在不同操作系统上的表现差异