开发者

Pass array of arrays to function as if it was individual arrays

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 t开发者_如何转开发hrough a foreach loop? Or is it just late and I'm missing something really obvious?


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜