I answered a duplicate before finding this page. My solutions below use ...$row
for the input data, but for this question just switch ...$rows
for $a, $b, $c
. (I have since deleted my other answer and hammered the duplicate question using this page.)
My thoughts on functional one-liners (I've split it and tabbed it for readability) are as follows. Note that early filtering will mean minimizing "useless data" handling and late filtering will make fewer function calls.
Late filtering with greedy/lazy/falsey filtering: (Demo)
var_export(
array_filter( #remove nulls
array_merge( #flatten the unpacked elements
...array_map( #unpack
null, #transpose
...$rows #transpose
) #unpack
) #flatten the unpacked elements
) #remove nulls
);
Condensed one-liner syntax: (Demo)
var_export(array_filter(array_merge(...array_map(null, ...$rows))));
Intermediate filtering with greedy/lazy/falsey filtering: (Demo)
var_export(
array_merge( #flatten the unpacked elements
...array_filter( #remove nulls from transposing then unpack
array_map( #transpose
null, #transpose
...$rows #transpose
) #transpose
) #remove nulls from transposing then unpack
) #flatten the unpacked elements
);
Or do early filtering... (with greedy/lazy/falsey filtering)
Code: (Demo)
var_export(
array_merge( #flatten the unpacked elements
...array_map( #unpack
function() { #transpose discarding nulls
return array_filter( #transpose discarding nulls
func_get_args() #transpose discarding nulls
); #transpose discarding nulls
}, #transpose discarding nulls
...$rows #transpose discarding nulls
) #unpack
) #flatten the unpacked elements
);
Or early filtering with greedy/lazy/falsey filtering and more "splatting": (Demo)
var_export(
array_merge( #flatten the unpacked elements
...array_map( #unpack
function(...$v) { #transpose discarding nulls
return array_filter($v); #transpose discarding nulls
}, #transpose discarding nulls
...$rows #transpose discarding nulls
) #unpack
) #flatten the unpacked elements
);
And here is the PHP7.4 version: (Demo)
var_export(
array_merge( #flatten the unpacked elements
...array_map( #unpack
fn(...$v) => array_filter($v), #transpose discarding nulls
...$rows #transpose discarding nulls
) #unpack
) #flatten the unpacked elements
);
Which condenses as:
var_export(array_merge(...array_map(fn(...$v) => array_filter($v), ...$rows)));