doubo4336 2013-01-09 03:18
浏览 20
已采纳

基于键将5个数组与php组合在一起

I have 5 arrays like this

print_r($_POST['ponumber']);
print_r($_POST['man_part_number']);
print_r($_POST['model']);
print_r($_POST['damaged']);
print_r($_POST['serial_number']);
print_r($_POST['skid']);

which produces

Array
(
    [0] => 111111
    [1] => 111111
    [2] => 111111
    [3] => 111111
)
Array
(
    [0] => 11C2555
    [1] => 11C2555
    [2] => 11C2555
    [3] => 11C2555
)
Array
(
    [0] => FORMS PRINTER 2500 SERIES
    [1] => FORMS PRINTER 2500 SERIES
    [2] => FORMS PRINTER 2500 SERIES
    [3] => FORMS PRINTER 2500 SERIES
)
Array
(
    [0] => 0
    [1] => 0
    [2] => 0
    [3] => 0
)
Array
(
    [0] => CNCQ202070
    [1] => CNCQ210800
    [2] => MY5203B1KQ
    [3] => CN1863Q0PQ
)
Array
(
    [0] => 1
    [1] => 1
    [2] => 1
    [3] => 1
)

I need to combine them based on keys so that I get 4 arrays total that look like this

Array
(
    [0] => 111111
    [1] => 11C2555
    [2] => FORMS PRINTER 2500 SERIES
    [3] => 0
    [4] => CNCQ202070
 )

and so on...

It needs to match each key in each array and combine them into one array. I was trying array_combine and array_merge but I don't think that was the right way to go. Anyone?

  • 写回答

4条回答 默认 最新

  • dsfds2343 2013-01-09 03:27
    关注
    $items = array();
    
    for($x = 0; $x < count($_POST['ponumber']); $x++){
        $item = array($_POST['ponumber']);
        $item[] = $_POST['ponumber'][$x];
        $item[] = $_POST['man_part_number'][$x];
        $item[] = $_POST['model'][$x];
        $item[] = $_POST['damaged'][$x];
        $item[] = $_POST['serial_number'][$x];
        $item[] = $_POST['skid'][$x];
        $items[] = $item;
    }
    

    Will give an array of the arrays you need. Note that this assumes that all arrays are the same size. You may need to add some checks if this is not the case.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?