更新:对不起,我想通了.. 我只取出 $value[0],所以它只有一个结果。需要更多的睡眠。非常感谢。我仍然愿意就更清洁的方式拆分数组提出建议。
$tdata
我有一个具有这种结构的数组:
Array
(
[] => Array
(
[0] => Array
(
[firstName] => test
[lastName] => test
[userName] => test@test.com
[password] => test
[course] => test
[role] => test
)
[1] => Array
(
[firstName] => test
[lastName] => test
[userName] => test@test.com
[password] => test
[course] => test
[role] => test
)
)
[delete] => Array
(
[0] => Array
(
[firstName] => test
[lastName] => test
[userName] => test@test.com
[password] => test
[course] => test
[role] => test
)
)
[update] => Array
(
[0] => Array
(
[firstName] => test
[lastName] => test
[userName] => test@test.com
[password] => test
[course] => test
[role] => test
)
)
[outrole] => Array
(
[0] => Array
(
[firstName] => test
[lastName] => test
[userName] => test@test.com
[password] => test
[course] => test
[role] => test
)
)
)
我正在尝试将其拆分为较小的数组。像这样:
foreach ($tdata as $key => $value) {
if ($key == '') {
$create[] = $value[0];
}elseif ($key == 'outrole') {
$outrole[] = $value[0];
}elseif ($key == 'delete') {
$delete[] = $value[0];
}elseif ($key == 'update') {
$update[] = $value[0];
}else{
$noaction[] = $value[0];
}
}
我认为,这样数组就会不断覆盖自己。print_r($create)
或任何其他数组总是只返回 1 个结果。可以启发我并告诉我我做错了什么吗?
如果有更好的方法,我也很想听听。
提前致谢!