3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = [ [15, 16, 8, 1], [2, 3, 4, 7], [9, 11, 19, 6] ]; function bubbleSortRowCol(&$arr) { $colCount = count($arr[0]); $rowCount = count($arr); $tempArr = []; $columnArr = []; foreach($arr as $key => $value) { $tempArr[$key] = bubbleSort($value); } for($i = 0; $i < $colCount; $i++) { $columnArr[$i] = bubbleSort(array_column($tempArr, $i)); } for($i = 0; $i < $rowCount; $i++) { $tempArr[$i] = bubbleSort(array_column($$columnArr, $i)); } $arr = $tempArr; } function bubbleSort($arr) { $n = sizeof($arr); for ($i = 1; $i < $n; $i++) { $flag = false; for ($j = $n - 1; $j >= $i; $j--) { if($arr[$j-1] > $arr[$j]) { $tmp = $arr[$j - 1]; $arr[$j - 1] = $arr[$j]; $arr[$j] = $tmp; $flag = true; } } if (!$flag) { break; } } return $arr; } function bSort($arr) { bubbleSortRowCol($arr); return $arr; } print_r(bSort($arr));
based on N6JLE
Output for 7.2.0
Notice: Array to string conversion in /in/87vXM on line 24 Notice: Undefined variable: Array in /in/87vXM on line 24 Warning: array_column() expects parameter 1 to be array, null given in /in/87vXM on line 24 Warning: sizeof(): Parameter must be an array or an object that implements Countable in /in/87vXM on line 32 Notice: Array to string conversion in /in/87vXM on line 24 Notice: Undefined variable: Array in /in/87vXM on line 24 Warning: array_column() expects parameter 1 to be array, null given in /in/87vXM on line 24 Warning: sizeof(): Parameter must be an array or an object that implements Countable in /in/87vXM on line 32 Notice: Array to string conversion in /in/87vXM on line 24 Notice: Undefined variable: Array in /in/87vXM on line 24 Warning: array_column() expects parameter 1 to be array, null given in /in/87vXM on line 24 Warning: sizeof(): Parameter must be an array or an object that implements Countable in /in/87vXM on line 32 Array ( [0] => [1] => [2] => )
Output for 7.1.10

Process exited with code 137.
Output for 5.5.24 - 7.1.7
Notice: Array to string conversion in /in/87vXM on line 24 Notice: Undefined variable: Array in /in/87vXM on line 24 Warning: array_column() expects parameter 1 to be array, null given in /in/87vXM on line 24 Notice: Array to string conversion in /in/87vXM on line 24 Notice: Undefined variable: Array in /in/87vXM on line 24 Warning: array_column() expects parameter 1 to be array, null given in /in/87vXM on line 24 Notice: Array to string conversion in /in/87vXM on line 24 Notice: Undefined variable: Array in /in/87vXM on line 24 Warning: array_column() expects parameter 1 to be array, null given in /in/87vXM on line 24 Array ( [0] => [1] => [2] => )
Output for 5.4.10 - 5.4.45
Fatal error: Call to undefined function array_column() in /in/87vXM on line 20
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/87vXM on line 3
Process exited with code 255.