一种更好的php数组合并

一种更好的php数组合并,php,arrays,multidimensional-array,array-merge,Php,Arrays,Multidimensional Array,Array Merge,我正在寻找一种更好的方法,无需对$justPrices[$I]的整数进行硬编码: $pricesResult = array_merge($justPrices[0], $justPrices[1], $justPrices[2], $justPrices[3]); $justPrices是一个多维数组,每个数组中包含4个“价格带”。$justPrices的数据如下: Array ( [0] => Array ( [0] => 40.95 [1] => 39.95 [2] =

我正在寻找一种更好的方法,无需对
$justPrices[$I]
的整数进行硬编码:

$pricesResult = array_merge($justPrices[0], $justPrices[1], $justPrices[2], $justPrices[3]);
$justPrices
是一个多维数组,每个数组中包含4个“价格带”。
$justPrices
的数据如下:

Array ( [0] => Array ( [0] => 40.95 [1] => 39.95 [2] => 39.45 [3] => 38.95 ) [1] => Array ( [0] => 45.80 [1] => 41.80 [2] => 41.50 [3] => 41.40 ) [2] => Array ( [0] => 45.95 [1] => 42.95 [2] => 41.95 [3] => 41.45 ) [3] => Array ( [0] => 50.00 [1] => 50.00 [2] => 50.00 [3] => 50.00 ) )
问题是,
$justPrices
中的数组数量将至少从2到10+不等。因此,我需要一种方法,使
array\u merge()
函数的参数根据
$justPrices
中的数组数量而变化。我打算使用这个简单的方法来获取
$justPrices
中的数组数量:

$justPricesMax = count($justPrices);

我可以为循环编写一个
,我仍然可以,我只是想知道对于表面上看起来相对简单的东西,是否有更好的方法

如果只想展平数组,可以使用调用
array\u merge
,将
$justPrices
的元素作为参数:

$flat = call_user_func_array('array_merge', $justPrices);
这相当于函数调用中的

$flat = array_merge($justPrices[0], $justPrices[1], … , $justPrices[count($justPrices)-1]);

@Gumbo包含所有价格的单个数组。后来我用它来表示平均价格,就是这样。妙极了。