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 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景