我有一个看起来像这样的数组:
$example = [
['rendered'][0]['rendereditem1']
['rendered'][4]['rendereditem2 and more']
['rendered'][2]['rendereditem3']
]
现在我想用foreach
进行迭代以获取0,4,2!
通常我会写:
foreach($example as $value){
print $value['rendered'][int which is the same everywhere];
}
但这显然不起作用,因为数组名称总是不同的......在这种情况下我怎么能迭代?
答案 0 :(得分:1)
只需添加第二个循环来迭代成员:
foreach($example as $value) {
foreach($value['rendered'] as $key=>$item) {
// Do what you want here, $key is 0,4,2 in your example
}
}