How to pass an array via $_GET in php?

Web Development

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?



Ans: It is possible to pass an array, associate array to http_build_query() and append the string that is resulting as the query string to the URL. Automatic parsing of the array takes place by PHP. So $_GET will contain an arrange on the receiving page. Let me give you an example as well.

$query_str = http_build_query(array(

    'k' => array(4,5,6)



If you want to unleash your potential in this competitive field, please visit the Web Development course page for more information, where you can find the Web Development tutorials and Web Development frequently asked interview questions and answers as well.


This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.