php把get参数放入数组_URL 通过Get方式传递数组参数(示例代码)

URL 通过Get方式传递数组参数

方法1:

?id=1&id=2&id=3

后台获取时,只需要reqeust.getParameterValues("id") 获取String数组。

http协议的要求

解析参数时,相同的key会覆盖前一个,

如果带[]会当成一维数组来处理,就不会覆盖了

直接可以url =url+"?str1="+arrayP[0]+"&str2="+arrayP[1];

Generally, when the target server uses a strong typed programming language like Java (Servlet), then you can just send them as multiple parameters with the same name. The API usually offers a dedicated method to obtain multiple parameter values as an array.

foo=value1&foo=value2&foo=value3

String[]foo =request.getParameterValues("foo");// [value1, value2, value3]

The request.getParameter("foo") will also work on it, but it‘ll return only the first value.

Stringfoo =request.getParameter("foo");// value1

And, when the target server uses a weak typed language like PHP or RoR, then you need to suffix the parameter name with braces [] in order to trigger the language to return an array of values instead of a single value.

foo[]=value1&foo[]=value2&foo[]=value3

$foo =$_GET["foo"];// [value1, value2, value3]echo is_array($foo);// true

In case you still use foo=value1&foo=value2&foo=value3, then it‘ll return only the first value.

$foo =$_GET["foo"];// value1echo is_array($foo);// false

Do note that when you send foo[]=value1&foo[]=value2&foo[]=value3 to a Java Servlet, then you can still obtain them, but you‘d need to use the exact parameter name including the braces.

String[]foo =request.getParameterValues("foo[]");// [value1, value2, value3]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值