将x,y坐标放在中间

时间:2011-11-15 15:17:29

标签: php

<?php
$startX = 2;
$startY = 5;

$fieldHeight = 6;
$fieldWidth = 6;

$player[2][5] = 1;


echo "<table>";
for ($y=$startY; $y<$fieldHeight+$startY+$fieldHeight; $y++) {
   echo "<tr>";
   for ($x=$startX; $x<$fieldWidth+$startX+$fieldWidth; $x++) {
       echo "<td>";
        if (isset($player[$x][$y])) {
            echo "UID: " . $player[$x][$y];
        } else {
            echo "(" . $x . ", " . $y . ")";
        }
       echo "</td>";
   }
   echo "</tr>";
}
echo "</table>";

输出:

UID: 1  (3, 5)  (4, 5)  (5, 5)  (6, 5)  (7, 5)  (8, 5)  (9, 5)  (10, 5) (11, 5) (12, 5) (13, 5)
(2, 6)  (3, 6)  (4, 6)  (5, 6)  (6, 6)  (7, 6)  (8, 6)  (9, 6)  (10, 6) (11, 6) (12, 6) (13, 6)
(2, 7)  (3, 7)  (4, 7)  (5, 7)  (6, 7)  (7, 7)  (8, 7)  (9, 7)  (10, 7) (11, 7) (12, 7) (13, 7)
(2, 8)  (3, 8)  (4, 8)  (5, 8)  (6, 8)  (7, 8)  (8, 8)  (9, 8)  (10, 8) (11, 8) (12, 8) (13, 8)
(2, 9)  (3, 9)  (4, 9)  (5, 9)  (6, 9)  (7, 9)  (8, 9)  (9, 9)  (10, 9) (11, 9) (12, 9) (13, 9)
(2, 10) (3, 10) (4, 10) (5, 10) (6, 10) (7, 10) (8, 10) (9, 10) (10, 10)    (11, 10)    (12, 10)    (13, 10)
(2, 11) (3, 11) (4, 11) (5, 11) (6, 11) (7, 11) (8, 11) (9, 11) (10, 11)    (11, 11)    (12, 11)    (13, 11)
(2, 12) (3, 12) (4, 12) (5, 12) (6, 12) (7, 12) (8, 12) (9, 12) (10, 12)    (11, 12)    (12, 12)    (13, 12)
(2, 13) (3, 13) (4, 13) (5, 13) (6, 13) (7, 13) (8, 13) (9, 13) (10, 13)    (11, 13)    (12, 13)    (13, 13)
(2, 14) (3, 14) (4, 14) (5, 14) (6, 14) (7, 14) (8, 14) (9, 14) (10, 14)    (11, 14)    (12, 14)    (13, 14)
(2, 15) (3, 15) (4, 15) (5, 15) (6, 15) (7, 15) (8, 15) (9, 15) (10, 15)    (11, 15)    (12, 15)    (13, 15)
(2, 16) (3, 16) (4, 16) (5, 16) (6, 16) (7, 16) (8, 16) (9, 16) (10, 16)    (11, 16)    (12, 16)    (13, 16)

正如你在左上角看到的那样,放置了UID:1,我希望它在中间,但我不知道如何......

我想我需要把坐标放在startX或者其他东西下面,但是如果有 - 坐标,我只会推出一个特定的测试,这可能吗?

1 个答案:

答案 0 :(得分:0)

好的

$startX = 2;
$startY = 5;

$player[2][5] = 1;

然后使用for$startX作为循环的基本整数,请求两个$startY循环。因此,根据您的$player[2][5]条款,要打印的第一个项目为$player[$startX][$startY](或if)。

演示您当前脚本出错的地方:更改$startX = 1;$startY = 1,UID将打印在$ x = 2和$ y = 5。