PHP中名称相同的不同元素

时间:2022-11-26 23:55:32

In PHP, I would like to know how to provide the same name to different elements and still echo them out individually. I think the array mechanism works here but I don’t know how.

在PHP中,我希望知道如何为不同的元素提供相同的名称,并仍然分别对它们进行回显。我认为数组机制在这里可以工作,但是我不知道怎么做。

echo "<input type='checkbox' name='seat[]' id='something'/>";
echo "<input type='checkbox' name='seat[]' id='something1'/>"  

Then to echo their values out I use the following:

然后我用下面的方法来回应他们的价值观:

<?php
if(isset($_POST['seat[]']))
    {
    echo ' ', $_POST['seat[]'] ; 
    }
?>

Please guide me!!

请指导我! !

1 个解决方案

#1


5  

It's just an array of data. You can access elements of it just like any other array:

它只是一个数据数组。你可以像其他数组一样访问它的元素:

foreach ($_POST['seat'] as $seat) {
    echo $seat . "<br>\n";
}

or using a numerical index:

或使用数值索引:

echo $_POST['seat'][0]; // value of the first submitted checkbox

#1


5  

It's just an array of data. You can access elements of it just like any other array:

它只是一个数据数组。你可以像其他数组一样访问它的元素:

foreach ($_POST['seat'] as $seat) {
    echo $seat . "<br>\n";
}

or using a numerical index:

或使用数值索引:

echo $_POST['seat'][0]; // value of the first submitted checkbox