douganbi7686 2014-09-08 21:18
浏览 34
已采纳

PHP - 如何合并未指定数量的数组?

Is it possible to merge non-specified number of array elements in PHP?

I received data through JSON string (n elements), then I used them to do n loops - each loop saves the result to a different array cell ($result[1], $result[2], $result[3], ... ,$result[n]). I would like to merge the results into a single array (I have to send single array through JSON). Everything works if I write manually array_merge ($result[1], $result[2], $result[3]), but I never know how many variables I will receive.

Thanks in advance

  • 写回答

1条回答 默认 最新

  • douseda0009 2014-09-08 21:22
    关注

    Try this:

    $yourListOfArrays = [$result[1], $result[2], ...];
    
    call_user_func_array('array_merge',$yourListOfArrays);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能