Pass array with keys via HTTP GET

故事扮演 提交于 2019-12-10 17:25:09

问题


I have tried to pass array data to the PHP script with request:

script.php?page=7&filter[key]=value

but didn't receive it in the script. Can I do so and if no - how can I pass array with HTTP GET?


回答1:


You can definitely pass array from url and to get the value on php page,

$testvar = $_GET['filter'];
echo $testvar['key'];

and just out of curiosity i tried to $_GET['filter']['value'] and it too worked !!!

and if you want to pass multiple array vals, you can use http_build_query




回答2:


Yes you will get those value in an array on script.php page

Just try to print the array value in the script.php page.

print_r($_GET['filter']);




回答3:


you have to just pass the data like this

script.php?page=7&filter=value

and use is_array() for checking that incoming data is array or not like this

is_array($_GET['filter'])

http://php.net/manual/en/function.is-array.php



来源:https://stackoverflow.com/questions/12639015/pass-array-with-keys-via-http-get

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!