在PHP中,有三種常見的方式來(lái)定義數(shù)組:
$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")
);
此外,還可以使用[]
語(yǔ)法來(lái)定義數(shù)組:
$fruits = ["apple", "banana", "orange"];
這是PHP 5.4版本及更高版本引入的簡(jiǎn)潔語(yǔ)法。