PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
<?php function rotate90degreesWithoutAdditionalSpace() { $matrix = [[1,2,3], [4,5,6], [7,8,9]]; $len = count($matrix); // Swap the rows columns. for($i=0; $i<$len; $i++) { for($j=$i; $j<$len; $j++) { $tmp = $matrix[$i][$j]; $matrix[$i][$j] = $matrix[$j][$i]; $matrix[$j][$i] = $tmp; } } // Swap the elements from both ends of each row until the centered element in the row. for($i=0; $i<$len; $i++) { for($j=0; $j<floor($len/2); $j++) { $tmp = $matrix[$i][$j]; $matrix[$i][$j] = $matrix[$i][$len-1-$j]; $matrix[$i][$len-1-$j] = $tmp; } } return $matrix; }
Copy Clear
Copy Format Clear
<?php $matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ]; var_export(array_map(fn() => array_reverse(func_get_args()), ...$matrix)); echo "\n---\n"; var_export(array_map(fn(...$col) => array_reverse($col), ...$matrix));
Show:  
Copy Clear