How can I pass one or more variables of type array to another page via $_GET?
I always passed variable values in the form ?a=1&b=2&c=3
What about passing a=[1,2,3] ?
Do I need to write a for loop and append all the values?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the
[]syntax to pass arrays through _GET:PHP understands this syntax, so
$_GET['a']will be equal toarray(1, 2, 3).You can also specify keys:
Multidimentional arrays work too:
http_build_query()does this automatically:An alternative would be to pass json encoded arrays:
And you can parse
awithjson_decode:And encode it again with json_encode:
Dont ever use
serialize()for this purpose. Serialize allows to serialize objects, and there is ways to make them execute code. So you should never deserialize untrusted strings.