我对多维数组的逻辑分组有问题,如下所示。
Array
(
[id] => Array
(
[0] => B
[1] => C
[2] => D
[3] => A
)
[value] => Array
(
[0] => 1500000
[1] => 200000
[2] => 250000
[3] => 100000
)
[desc] => Array
(
[0] => DESC B
[1] => DESC C
[2] => DESC D
[3] => DESC A
)
[type] => Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
)
[userid] => 1312
)
我想将每行按名称分组的每一行插入数据库,例如:
id | name | value | desc | type | userid
---------------------------------------------
1 | A | 100000 | DESC A | 1 | 1312
2 | B | 150000 | DESC B | 1 | 1312
3 | C | 200000 | DESC B | 1 | 1312
我是否使用双foreach按名称或其他任何方式分组来解决这个问题?
答案 0 :(得分:0)
最简单的解决方案是回收一个数组的键以输出其他数组并创建新组
foreach($id as $i => $dummy){
$data = array($id[$i], $value[$i], $desc[$i], $type[$i], $userid);
}