这是我的简单代码:
<?php
$components=array(
1 => 'Carrot', 'Apple', 'Orange',
2 => 'Boiled Egg', 'Omelet',
3 => 'Ice Cream', 'Pancake', 'Watermelon'
);
echo'<pre>';
var_dump($components);
echo'</pre>';
输出:
array(6) {
[1]=>
string(6) "Carrot"
[2]=>
string(10) "Boiled Egg"
[3]=>
string(9) "Ice Cream"
[4]=>
string(6) "Omelet"
[5]=>
string(7) "Pancake"
[6]=>
string(10) "Watermelon"
}
'Apple'
&amp; 'Orange'
?答案 0 :(得分:3)
制作一个这样的数组,
$components=array(
1 => ['Carrot', 'Apple', 'Orange'],
2 => ['Boiled Egg', 'Omelet'],
3 => ['Ice Cream', 'Pancake', 'Watermelon']
);
现在检查你的阵列。
答案 1 :(得分:2)
你需要像这样组织你的数组:
$components = array(
1 => array(
1 => 'Carrot',
2 => 'Apple',
3 => 'Orange'
),
2 => array(
1 => 'Boiled Egg',
2 => 'Omelet'
),
3 => array(
1 => 'Ice Cream',
2 => 'Pancake',
3 => 'Watermelon'
),
);
然后您就可以获得:$components[1][2] = 'Apple'
答案 2 :(得分:1)
根据您给定的语法,它形成一个单维数组,而不是多维数组。
试试这个:
$components=array(
1 => array('Carrot', 'Apple', 'Orange'),
2 => array('Boiled Egg', 'Omelet'),
3 => array('Ice Cream', 'Pancake', 'Watermelon')
);
答案 3 :(得分:0)
<?php
$components=array(
1 => ['Carrot', 'Apple', 'Orange'],
2 => ['Boiled Egg', 'Omelet'],
3 => ['Ice Cream', 'Pancake', 'Watermelon']
);
echo "<pre>";
print_R($components);
&GT;