drrrdo0802 2019-03-14 09:08
浏览 69
已采纳

在数组块之后在php中合并多维数组

Here is my arrays after array chunk by 2

$a = array(0 => array("testA1", "testA2"), 1 =>array("testA3", "testA4"));

$b = array(0 => array("testB1", "testB2"), 1 =>array("testB3", "testB4"));

$c = array(0 => array("testC1", "testC2"), 1 =>array("testC3", "testC4"));

I want to merge these arrays in below format.

$result = array("testA1","testA2","testB1","testB2", "testC1", "testC2", 
"testA3", "testA4", "testB3", "testB4", "testC3", "testC4"
);

Is there any in-built function available or how to solve this?.

  • 写回答

2条回答 默认 最新

  • dongshi6969 2019-03-14 09:11
    关注

    Use array_merge twice with ... syntax:

    print_r(array_merge(...array_merge($a, $b, $c)));
    
    // 2nd version
    $parts = [];
    foreach($a as $k => $v) {
        $parts[$k] = array_merge($a[$k], $b[$k], $c[$k]);
    }
    print_r(array_merge(...$parts));
    
    // hard to understand version:
    $parts = array_map(null, $a, $b, $c);
    print_r(array_merge(...array_merge(...$parts)));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥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 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看