我有一个不同部门的多维数组,并且想使用 foreach 循环遍历它,但由于某种原因,foreach 循环在每次迭代中都会抓取第一个键下的值。
数组如下所示:
$departmentArray =
Array
(
[0] => Array
(
[dpt_id] => 5
[dpt_name] => Administration
[dpt_employees] => Array
(
[0] => Array
(
[started] => 2000-06-01
[stopped] => 9999-99-99
[empl_id] => 21
)
[1] => Array
(
[started] => 2000-06-01
[stopped] => 2010-01-01
[empl_id] => 23
)
)
)
[1] => Array
(
[dpt_id] => 6
[dpt_name] => Warehouse
[dpt_employees] => Array
(
[0] => Array
(
[started] => 2000-10-01
[stopped] => 2012-01-01
[empl_id] => 30
)
[1] => Array
(
[started] => 2007-10-17
[stopped] => 9999-99-99
[empl_id] => 197
)
)
)
)
foreach 循环如下所示:
foreach($departmentArray as $key => $value) {
print_r($key);
print_r($value['dpt_name']);
}
这打印:
0 Administration 1 Administration.
有谁知道,为什么循环不会在数组中向前移动并在第二次迭代期间获取键/索引 1 下的值(仓库)?