Php – How to extract all 2nd level values (leaf nodes) from a 2-dimensional array and join with commas

multidimensional-arrayphp

How can I get the list of values from my array:

[data] => Array
        (
            [5] => Array
                (
                    [0] => 19
                    [1] => 18
                    [2] => 20
                )

            [6] => Array
                (
                    [0] => 28
                )

        )

Expected output result string will be: 19,18,20,28

Thanks!

Best Solution

With one line, no loop.

echo implode(',', call_user_func_array('array_merge', $data));

Try it here.