"; if (!isset($_POST['submit'])) { exit(); } $n = $_POST['n']; $m = $_POST['m']; $x = $m; $y = 1; $array = array_fill(0, 101, array_fill(0, 101, 0)); $banghyang = 3; for ($i = 1; $i <= $n * $m; $i++) { $array[$y][$x] = $i; if ($banghyang == 0) { if ($x + 1 > $m || $array[$y][$x + 1]) { $banghyang = 3; $y++; } else { $x++; } } else if ($banghyang == 1) { if ($x - 1 < 1 || $array[$y][$x - 1]) { $banghyang = 2; $y--; } else { $x--; } } else if ($banghyang == 2) { if ($y - 1 < 1 || $array[$y - 1][$x]) { $banghyang = 0; $x++; } else { $y--; } } else if ($banghyang == 3) { if ($y + 1 > $n || $array[$y + 1][$x]) { $banghyang = 1; $x--; } else { "> "; if (!isset($_POST['submit'])) { exit(); } $n = $_POST['n']; $m = $_POST['m']; $x = $m; $y = 1; $array = array_fill(0, 101, array_fill(0, 101, 0)); $banghyang = 3; for ($i = 1; $i <= $n * $m; $i++) { $array[$y][$x] = $i; if ($banghyang == 0) { if ($x + 1 > $m || $array[$y][$x + 1]) { $banghyang = 3; $y++; } else { $x++; } } else if ($banghyang == 1) { if ($x - 1 < 1 || $array[$y][$x - 1]) { $banghyang = 2; $y--; } else { $x--; } } else if ($banghyang == 2) { if ($y - 1 < 1 || $array[$y - 1][$x]) { $banghyang = 0; $x++; } else { $y--; } } else if ($banghyang == 3) { if ($y + 1 > $n || $array[$y + 1][$x]) { $banghyang = 1; $x--; } else { "> "; if (!isset($_POST['submit'])) { exit(); } $n = $_POST['n']; $m = $_POST['m']; $x = $m; $y = 1; $array = array_fill(0, 101, array_fill(0, 101, 0)); $banghyang = 3; for ($i = 1; $i <= $n * $m; $i++) { $array[$y][$x] = $i; if ($banghyang == 0) { if ($x + 1 > $m || $array[$y][$x + 1]) { $banghyang = 3; $y++; } else { $x++; } } else if ($banghyang == 1) { if ($x - 1 < 1 || $array[$y][$x - 1]) { $banghyang = 2; $y--; } else { $x--; } } else if ($banghyang == 2) { if ($y - 1 < 1 || $array[$y - 1][$x]) { $banghyang = 0; $x++; } else { $y--; } } else if ($banghyang == 3) { if ($y + 1 > $n || $array[$y + 1][$x]) { $banghyang = 1; $x--; } else { ">
<body>
<form action="index.php" method="post">
<input type="text" name="n" placeholder="n">
<input type="text" name="m" placeholder="m">
<input type="submit" name="submit" value="Submit">
<?php
echo "<br>";
if (!isset($_POST['submit'])) {
exit();
}
$n = $_POST['n'];
$m = $_POST['m'];
$x = $m;
$y = 1;
$array = array_fill(0, 101, array_fill(0, 101, 0));
$banghyang = 3;
for ($i = 1; $i <= $n * $m; $i++) {
$array[$y][$x] = $i;
if ($banghyang == 0) {
if ($x + 1 > $m || $array[$y][$x + 1]) {
$banghyang = 3;
$y++;
} else {
$x++;
}
} else if ($banghyang == 1) {
if ($x - 1 < 1 || $array[$y][$x - 1]) {
$banghyang = 2;
$y--;
} else {
$x--;
}
} else if ($banghyang == 2) {
if ($y - 1 < 1 || $array[$y - 1][$x]) {
$banghyang = 0;
$x++;
} else {
$y--;
}
} else if ($banghyang == 3) {
if ($y + 1 > $n || $array[$y + 1][$x]) {
$banghyang = 1;
$x--;
} else {
$y++;
}
}
}
for ($i = 1; $i <= $n; $i++) {
for ($j = 1; $j <= $m; $j++) {
echo $array[$i][$j] . " ";
}
echo "<br>";
}
?>
</form>
</body>