如何解析发布值?

发布于 2024-12-22 16:53:40 字数 767 浏览 0 评论 0原文

我有以下代码:

<input type="checkbox" name="pay[]"  value="
               <?php 
                         echo $invoiceArr[$record_count].";";
                         echo $TotalArr[$record_count].";";
                         echo $amount_dueArr[$record_count];
                  ?>
                  " onClick="checkTotal()"/>

如何解析:

       echo $invoiceArr[$record_count].";";
       echo $TotalArr[$record_count].";";
       echo $amount_dueArr[$record_count];

当使用 POST 提交表单时?

非常感谢

我怎样才能只获取一个元素

   echo $amount_dueArr[$record_count];

并将其传递给:

var elements = document.getElementsByName("pay[]");

谢谢朋友

I have the following code:

<input type="checkbox" name="pay[]"  value="
               <?php 
                         echo $invoiceArr[$record_count].";";
                         echo $TotalArr[$record_count].";";
                         echo $amount_dueArr[$record_count];
                  ?>
                  " onClick="checkTotal()"/>

How can I parse:

       echo $invoiceArr[$record_count].";";
       echo $TotalArr[$record_count].";";
       echo $amount_dueArr[$record_count];

When the form is being submited with POST?

Many thanks

How can I get only one element

   echo $amount_dueArr[$record_count];

and pass it into :

var elements = document.getElementsByName("pay[]");

Thanks mates

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

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

发布评论

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

评论(4

誰認得朕 2024-12-29 16:53:40

由于您使用 pay[] 作为表单名称,我相信您尝试进行数组表单输入。要读取数组表单输入,您只需使用它的键来读取它。

一点背景知识:

您可以像这样创建数组:

$data[] = "1";
$data[] = "2";

从上面的代码中,您将得到包含 2 个元素的数组 $data

print_r($data);
Array
(
    [0] => 1
    [1] => 2
)

返回到您的问题。要解析它,您所要做的就是循环遍历它:

for( $i = 0; $i < count( $_POST['pay'] ); $i++)
{
    $data = $_POST['pay'][ $i ];
    list($invoice, $total, $amount_due) = explode(";", $data);
    echo "Incoive: $invoice || Total: $total || Amount due: $amount_due";
}

Since you use pay[] as form name, I believe you try to do arrayed form input. To read arrayed form input, you just have to read it by using it's key.

A little bit of background:

You can create array like this:

$data[] = "1";
$data[] = "2";

From code above, you'll ended up with array $data with 2 element:

print_r($data);
Array
(
    [0] => 1
    [1] => 2
)

Back to your problem. To parse it, all you have to do is, loop through it:

for( $i = 0; $i < count( $_POST['pay'] ); $i++)
{
    $data = $_POST['pay'][ $i ];
    list($invoice, $total, $amount_due) = explode(";", $data);
    echo "Incoive: $invoice || Total: $total || Amount due: $amount_due";
}
森林很绿却致人迷途 2024-12-29 16:53:40

这看起来像是不寻常的做事方式,但你可以通过爆炸来解析它。

list($invoice, $total, $amount_due) = explode(";", $_POST['pay'][0]);

That looks like unusual way to do things but you can parse it by exploding.

list($invoice, $total, $amount_due) = explode(";", $_POST['pay'][0]);
无名指的心愿 2024-12-29 16:53:40

首先,我将输入的名称更改为 name=pay

然后在 php 中您将执行以下操作:

$data = explode(';', $_POST['pay']);

First of all, I would change the name of the input to name=pay

Then in php you would do the following:

$data = explode(';', $_POST['pay']);
甜柠檬 2024-12-29 16:53:40

$_GET$_POST 执行 var_dump,您就会看到。
此外,我认为你误解了你想要做什么。
您需要三个名为 pay[] 的元素,每个元素只有您拥有的值之一

$invoiceArr[$record_count]
$TotalArr[$record_count]
$amount_dueArr[$record_count]

Do a var_dump on $_GET or on $_POST and you'll see.
Besides, I think you are mis-understanding what you try to do.
You need three elements with the name pay[], and each of them will have only ONE of the values you have

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