douyan6548 2011-05-25 05:17
浏览 42
已采纳

传递数组数组,就像它是单个数组一样

I have a variable that contains an array. That array contains X number of nearly identical arrays that I want to merge together.

But since they're already in an array variable, I can't pass it to array_merge() like this:

array_merge( $AoA );

What I'd like to do is this, but I can't because I don't know how many items are in the array:

array_merge(
  $AoA[0],
  $AoA[1],
  $AoA[2],
  // etc ...
);

Is there a short hand I can use to accomplish this without having to run them through a foreach loop? Or is it just late and I'm missing something really obvious?

  • 写回答

1条回答 默认 最新

  • drk7700 2011-05-25 05:19
    关注

    Use call_user_func_array(), passing in array_merge as a string and your array of arrays, which the function then treats as an array of arguments to the function:

    call_user_func_array('array_merge', $AoA);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本