Written by Sean Behan on Fri Sep 28th 2018

There is no built in function for taking a multi dimensional array in PHP and flattening it into a single array. However, it's pretty easy to accomplish in a one liner. Here is the code

    $a = [['a', 'b', 'c'], ['1', '2', '3']];
    $b = array_merge(...array_values($a));
    // => ['a', 'b', 'c', '1', '2', '3']

This only works for PHP ~> 7

Tagged with..
#php #arrays #merge #flatten #one liners

Just finishing up brewing up some fresh ground comments...