3v4l.org

run code in 300+ PHP versions simultaneously
<?php $matrix = [ [11, 12, 13, 14, 15], [21, 22, 23, 24, 25], [31, 32, 33, 34, 35], [41, 42, 43, 44, 45], [51, 52, 53, 54, 55] ]; echo "До:\n"; foreach($matrix as $_) { foreach($_ as $item) echo $item . ' '; echo PHP_EOL; } echo "\n"; for ($i = 0; $i < count($matrix); $i++) { for ($j = $i + 1; $j < count($matrix); $j++) { $temp = $matrix[$i][$j]; $matrix[$i][$j] = $matrix[$j][$i]; $matrix[$j][$i] = $temp; } } echo "После:\n"; foreach($matrix as $innerArray){ foreach($innerArray as $item){ echo $item . ' '; } echo PHP_EOL; }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.28, 7.4.0 - 7.4.13, 8.0.0 - 8.0.3
До: 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45 51 52 53 54 55 После: 11 21 31 41 51 12 22 32 42 52 13 23 33 43 53 14 24 34 44 54 15 25 35 45 55