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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)