[英]PHP Get multiple values from GET with same name
I have a PHP page that will be sent (via GET) a variable number of variables with the same name. 我有一个PHP页面,该页面将(通过GET)发送同名变量。
ie 即
&color=Blue&color=Green&color=Black etc. &color =蓝色&color =绿色&color =黑色等
Is there an easy way to iterate through these? 有没有简单的方法可以遍历这些?
I dont think without using array you cant retrieve data of same name. 我认为不使用数组就无法检索相同名称的数据。 Example
例
<input type="text" name="color[]" value="blue">
<input type="text" name="color[]" value="green">
<input type="text" name="color[]" value="black">
now datas will pass like this 现在数据将像这样通过
?color[]=Blue&color[]=Green&color[]=Black
$color=$_GET['color'];
print_r($color);
Array
(
[color] => Array
(
[0] => Blue
[1] => Green
[2] => Black
)
)
For a variable number of "grouped" values, you can use a query string like this: 对于可变数量的“分组”值,可以使用如下查询字符串:
?color[]=Blue&color[]=Green&color[]=Black
and you'll get an array in your $_GET
: 然后您将在
$_GET
得到一个数组:
print_r($_GET);
Array
(
[color] => Array
(
[0] => Blue
[1] => Green
[2] => Black
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.