如何编写PHP代码来手动创建此数组?
Array (
[0] => Array
(
[Id] => 2
[Fruit] => Apple
)
[1] => Array
(
[Id] => 5
[Fruit] => Orange
)
)
答案 0 :(得分:3)
$arr = array();
$arr[] = array("Id" => 2, "Fruit" => "Apple");
$arr[] = array("Id" => 5, "Fruit" => "Orange");
答案 1 :(得分:1)
$array =array(
array('Id'=>2, 'Fruit'=>'Apple'),
array('Id'=>5, 'Fruit'=>'Orange')
);
NB:数组键区分大小写。
答案 2 :(得分:1)
$array = array();
$array[] = array(
'id'=>3,
'Fruit'=>'Orange'
);
$array[] = array(
'id'=>7,
'Fruit'=>'Banana'
);