3v4l.org

run code in 300+ PHP versions simultaneously
<?php function spiralmatrix($arr) { return $arr ? array_merge( array_shift($arr), spiralmatrix(array_reverse(transpose($arr))) ) : $arr; } function transpose($arr) { return $arr ? @!$arr[1] ? array_chunk($arr[0], 1) : array_map(null, ...$arr) : $arr; } print_r(spiralmatrix([])); print_r(spiralmatrix([[1]])); print_r(spiralmatrix([[1,2],[4,3]])); print_r(spiralmatrix([[1,2,3],[8,9,4],[7,6,5]])); print_r(spiralmatrix([[1,2,3,4],[12,13,14,5],[11,16,15,6],[10,9,8,7]])); print_r(spiralmatrix([[1,2,3,4],[10,11,12,5],[9,8,7,6]]));
Output for git.master_jit, git.master, rfc.property-hooks
Array ( ) Array ( [0] => 1 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 [12] => 13 [13] => 14 [14] => 15 [15] => 16 ) Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 8 [8] => 9 [9] => 10 [10] => 11 [11] => 12 )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
154.99 ms | 407 KiB | 5 Q