1

我有一个看起来像这样的数组:

$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];
}

但这显然不起作用,因为数组名称总是不同的......在这种情况下我怎么能迭代?

4

1 回答 1

1

只需添加第二个循环来迭代成员:

foreach($example as $value) {
  foreach($value['rendered'] as $key=>$item) {
    // Do what you want here, $key is 0,4,2 in your example
  }
}
于 2013-05-09T12:58:00.060 回答