【发布时间】:2013-04-29 11:30:53
【问题描述】:
我已经设置了一个关联数组(带有用于测试的虚拟数据),如下所示:
// To hold dropdown filter options
$results['filters'] = array('Client' => array( array('a' => '1') ),
'Project' => array( array('b' => '2') ),
'Status' => array( array('c' => '3') ),
'User' => array( array('d' => '4') )
);
谁能告诉我为什么会这样:
// Add 'All' option to the top of each filter dropdown
foreach($results['filters'] as $filter_key => $filter_value) {
$results['filters'][$filter_key][] = array('name' => 'All');
}
但这不是:
// Add 'All' option to the top of each filter dropdown
foreach($results['filters'] as $filter_key => $filter_value) {
$filter_value[] = array('name' => 'All');
}
当我在循环内执行print_r($results) 时,它似乎正在工作(将行附加到现有数据),但在循环外检查它会使循环似乎对数组没有影响。
谢谢
【问题讨论】:
标签: php arrays loops multidimensional-array foreach