总的noob在这里。我有一个数组,看起来像:array_slice - 这是怎么来的,这在foreach里不起作用
Array
(
[15] => Array
(
[0] => Array
(
[id] => 5216
[name] => Grow your own Irish Shamrock gifts set
[ordered] => 473
[image] => FunShamrockPot.jpg
)
[1] => Array
(
[id] => 5217
[name] => Irish Shamrock Seeds
[ordered] => 357
[image] => FunShamrockSeed.jpg
)
[2] => Array
(
[id] => 5759
[name] => Ireland Fleece with Shamrock Badge
[ordered] => 1
[image] => IrelandFleeceShamrocks.jpg
)
)
[31] => Array
(
[0] => Array
(
[id] => 5081
[name] => Tartan Guinness Flat Cap
[ordered] => 356
[image] => GuinnessTartanFlatCap.jpg
)
[1] => Array
(
[id] => 4894
[name] => Black signature emblem Guinness baseball hat
[ordered] => 176
[image] => GuinnessSigBBHat.jpg
)
的数组称为$产品,我想,换句话说,只是打印出每个顶阵列中的第一个五年阵列(如果是有道理的),数组[15] < - 前15个阵列下15,阵列[31] < - 前5个阵列在这里。
我想要的代码是:
foreach($products as $key=>$value) {
array_slice($value, 0, 5);
foreach($value as $product) {
echo $product['name'] . '<br/>';
}
echo '<br/>';
}
我想不通为什么array_slice将无法正常工作,我究竟做错了什么?
谢谢! array_slice怎么会不工作? – 2012-04-20 16:11:18
@hugo河马看到我的编辑 – squarephoenix 2012-04-20 16:14:35