A better php array_merge

后端 未结 1 623
盖世英雄少女心
盖世英雄少女心 2020-12-10 18:38

I am looking to do this a better way without the need to hardcode the integers for $justPrices[$i]:

$pricesResult = array_merge($justPrices[0],          


        
相关标签:
1条回答
  • 2020-12-10 19:06

    If you just want to flatten the array, you can use call_user_func_array to call array_merge with the elements of $justPrices as parameters:

    $flat = call_user_func_array('array_merge', $justPrices);
    

    This is equivalent to a the function call:

    $flat = array_merge($justPrices[0], $justPrices[1], … , $justPrices[count($justPrices)-1]);
    
    0 讨论(0)
提交回复
热议问题