任何想法为什么这不会打印出来

发布于 2024-08-30 12:24:19 字数 549 浏览 4 评论 0原文

修改 php 似乎无法打印出我想要的值

有什么想法吗?

谢谢

<form action="revision.php" method="GET">
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type="Submit" name="Calcuate"/>
</form>

<?php 
if(isset($_GET['number'])){
    $amount = count($number);

    for($i=0; $i < $amount; $i++){
        echo $number[$i];
    }
}
?>

Revising for php and cant seem to get this to print the values out that i want

Any ideas?

Thanks

<form action="revision.php" method="GET">
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type=“text” name=“number[]”/>
<input type="Submit" name="Calcuate"/>
</form>

<?php 
if(isset($_GET['number'])){
    $amount = count($number);

    for($i=0; $i < $amount; $i++){
        echo $number[$i];
    }
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甜尕妞 2024-09-06 12:24:20

编辑:我的答案是完全错误的。请参阅下面评论中的@rmarimon。

文本字段无法映射到数组。您必须将它们命名为难看的名称,例如“number1”、“number2”等,然后使用 $_GET['number1'] + ... 将它们相加。

EDIT: My answer is completely wrong. See @rmarimon in comments below.

Text fields can't be mapped to an array. You'll have to name them something ugly like "number1", "number2", etc and add them up with $_GET['number1'] + ...

青柠芒果 2024-09-06 12:24:20
 <form action="revision.php" method="GET" enctype="multipart/form-data">

将形式更改为此。
为此必须使用多部分标记,

您还需要使用它来进行文件上传

和打印,

foreach ($_GET['number'] AS $key => $value)
{
    echo "$key => $value";
}

因为数组可以是 number[1] ->数量[3]

 <form action="revision.php" method="GET" enctype="multipart/form-data">

Change form to this.
The multipart tag must be used for this

you also need this for file uploads

and for printing use this

foreach ($_GET['number'] AS $key => $value)
{
    echo "$key => $value";
}

because the array can be number[1] -> number[3]

污味仙女 2024-09-06 12:24:20

它不在您的代码中,但您是否有

$number = $_GET["number"]

您正在做的事情是正确的方法。这与另一个问题类似。

It is not in your code but do you have

$number = $_GET["number"]

What you are doing is the correct way. This is similar to this other question.

魄砕の薆 2024-09-06 12:24:20

在我看来,您应该在代码中更改一些内容,首先是字段的名称,您尝试将它们命名为 number[0]、number[1]、number[2]但它不会那样工作,请尝试以不同的方式命名它们,或者尝试创建一个 FOR cicle 来创建具有这些自定义名称的字段。其次,为了将 $_GET 变量中的数组保存到 $number 变量中,您需要这样的内容:

if(isset($_GET['number']))
{
    $number = $_GET['number'];
    $amount = count($number);
    for( $i = 0 ; $i < $amount ; $i++ )
        echo $number[$i];
}

希望这会有所帮助,如果您仍然遇到问题,请尝试发布或描述上下文以及您的想法形式和数组。

The way I see it, there's a couple things you should change in your code, first, the names of the fields, you're trying to name them number[0], number[1], number[2] from the looks of it but it won't work that way, try naming them differenty or try to make a FOR cicle to create the fields with those custom names. Second, in order to save the array coming in the $_GET variable into the $number variable you need something like this:

if(isset($_GET['number']))
{
    $number = $_GET['number'];
    $amount = count($number);
    for( $i = 0 ; $i < $amount ; $i++ )
        echo $number[$i];
}

Hope this helps, if you're still having problems try posting or describing the context and what you have in mind for the form and the array.

锦上情书 2024-09-06 12:24:19

我认为您的代码的实际问题是引号“是错误的,您使用的是“和”而不是“。更换它们,一切都会正常。

I think the actual problem with your code is that the quotation marks " are wrong you are using “ and ” instead of ". Replace those and everything will work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文