【发布时间】:2018-08-16 23:15:31
【问题描述】:
我有一个表格:
<form action="index.php" method="post">
具有多个选择输入
<select class="form-control" id="location" name="location[]" >
<option selected disabled value="">Choose Location</option>
<option value="closing">Closing Station</option>
<option value="device">Device/ROF</option>
<option value="merch1">General Merch 1</option>
<option value="merch2">General Merch 2</option>
</select>
<input type="hidden" name="image_name[]" value="<?php echo $file; ?>" />
我在提交表单时有这个数组:
Array (
[location] => Array (
[0] => closing
[1] => merch1
[2] => merch2 )
[image] => Array (
[0] => AL-AL.jpg
[1] => AL-AN.jpg
[2] => AL-AV.jpg
[3] => AL-CA.jpg
[4] => AL-CL.jpg
[5] => AL-CM.jpg )
[submit] => Submit
)
我希望 PHP 中的输出是这样的:location[0] 和 image[0] 等: 这是我的代码:
<?php
if (isset($_POST['submit'])){
foreach ($_POST['location'] as $location) {
foreach ($_POST['image_name'] as $image) {
echo "you have selected $image to go to this location: $location <br/>";
}
}
}
}
?>
这是当前输出:
you have selected AL-AL.jpg to go to this location: closing
you have selected AL-AN.jpg to go to this location: closing
you have selected AL-AV.jpg to go to this location: closing
you have selected AL-CA.jpg to go to this location: closing
you have selected AL-CL.jpg to go to this location: closing
you have selected AL-CM.jpg to go to this location: closing
you have selected AL-AL.jpg to go to this location: merch2
you have selected AL-AN.jpg to go to this location: merch2
you have selected AL-AV.jpg to go to this location: merch2
you have selected AL-CA.jpg to go to this location: merch2
you have selected AL-CL.jpg to go to this location: merch2
you have selected AL-CM.jpg to go to this location: merch2
它现在似乎是一个永恒的循环。我知道有一种方法可以匹配 [] 值上的每个数组,然后只在匹配的地方输出,但我想不通。
【问题讨论】: