在PHP中,有多种方式可以定义数组,包括:
$array = array("apple", "banana", "orange");
$array = ["apple", "banana", "orange"];
$array = array("name" => "John", "age" => 25, "city" => "New York");
$array = ["name" => "John", "age" => 25, "city" => "New York"];
$array = range(1, 10); // 创建一个包含1到10的整数数组
$string = "apple,banana,orange";
$array = explode(",", $string); // 将字符串拆分为数组
$name = "John";
$age = 25;
$city = "New York";
$array = compact("name", "age", "city"); // 创建一个关联数组,键名为变量名,键值为变量值
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: php pluck能处理多维数组吗