本文介绍了如何从单个< select>获取多个值HTML / PHP中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我在HTML表单中有一个标准的选择选项,但我想要做的是将多个值从一个选项值

Alright, so what I have is a standard select option in an HTML form, but what I'm trying to do is send over multiple values to the receiving PHP script from a single option value.

像这样的东西(我知道这是不正确的):

Such as something like this (I know it's incorrect):

<select name="size" id="size" type="text">
<option value="3" value="5" >3 Inches by 5 Inches</option>
<option value="6" value="4" >6 Inches by 4 Inches</option>
<option value="8" value="10" >8 Inches by 10 Inches</option>
</select>

然后在接收PHP脚本时,它可能会得到某种size [1],size [2]或其他。如果有人知道如何做到这一点,任何帮助都会很棒。我已经进行了相当广泛的搜索,但我没有看到任何相似的东西。再次感谢!

And then on the receiving PHP script it would perhaps get some sort of "size[1], size[2]" or something. If anybody knows how to do this, any help would be terrific. I've searched around quite extensively, but I haven't seen anything quite like this. Thanks again!

推荐答案

您可以将值中的两个值传递给

you can pass the two values in the value

<select name="size" id="size" type="text">
    ....
    <option value="6x4" >6 Inches by 4 Inches</option>
</select>

在后端,您可以拆分它以获取值

and in the backend you can split it to get the value

list($x,$y) = explode("x",$_GET['size']);  // or POST

echo $x; // 6
echo $y; // 4

这篇关于如何从单个&lt; select&gt;获取多个值HTML / PHP中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 16:43