doutao1939 2015-12-07 22:08
浏览 28
已采纳

来自网格的PHP多方向数组

I'm creating a crossword page on my site, I produce a grid (form) with 8 x 8 input boxes. when I fill in the answers they are sent to a page to assess them but this is where i have the problems.

the values are sent using form method GET, so if the top line read q,w,e,r,t, , ,y then it would pass this over like this :-

submit.php?0[0]=q&0[1]=w&0[2]=e&0[3]=r&0[4]=t&0[5]=&0[6]=&0[7]=y&1[0]

But when I put the values into an array, the empty values are left out, so when printing out the array it reads as "q,w,e,r,t,y" instead of "q,w,e,r,t, , ,y"

I currently fill the array like this :- $one = $_GET['0'];

My HTML form is:

<form action='submit.php' method='get' name='xword' id='xword1'> <?php

$array=array(
    array("h","e","l","l","o","0","0","0"),
    array("e","0","0","0","0","0","0","0"),
    array("l","0","0","0","0","0","0","0"),
    array("l","0","0","0","0","0","0","0"),
    array("o","0","0","0","0","0","0","0"),
    array("0","0","0","0","0","0","0","0"),
    array("0","0","0","0","0","0","0","0"),
    array("0","0","0","0","0","0","0","0"),
);

$X = 0;
while ($X < "8") {
    $Y = 0;
    while ($Y < "8") {
        if ($array[$X][$Y] == "0") {
            echo "<input type='text' id='text' name='" . $X . "[$Y]' class='blank'>";
        } else {
            echo "<input type='text' id='text' name='" . $X . "[$Y]' class='text'>";
        }
        $Y++;
    }
    echo "<br />";
    $X++;
}
?> <input type='submit' value='Submit'>

Where am I going wrong?

  • 写回答

1条回答 默认 最新

  • dq_1984 2015-12-07 22:29
    关注

    I don't see the empty spaces within the array being left out.

    This is the output of print_r($_GET) when I type qwer in the first four text fields and ty in the last two in the first row.

    Getting the data with $one = $_GET['0']; works fine (without quotes work too), and when I implode the first row, it outputs exactly what you had expected.

    echo implode(', ', $_GET[0]);
    
    OUTPUT: q, w, e, r, , , t, y
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制