3v4l.org

run code in 300+ PHP versions simultaneously
<?php $f=fn($a,$f)=>$a?[...array_shift($a),...$f(array_reverse($a?next($a)?array_map(null,...$a):array_chunk($a[0],1):$a),$f)]:$a; print_r( $f([[1, 2, 3, 4], [12, 13, 14, 5], [11, 16, 15, 6], [10, 9, 8, 7]], $f) );

preferences:
81.62 ms | 412 KiB | 5 Q