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 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置