Skip to content

URL GET vars to PHP Array

Sometimes you will need to retrieve the GET variables passed into the current page URI or you will have a URL string to work from which contains certain GET variables, the below method helps a lot to convert them into an array which you can easily manipulate later.

$url = $_SERVER["REQUEST_URI"]; parse_str(parse_url($url, PHP_URL_QUERY), $array);
Code language: PHP (php)

$array is now an array of all the GET variables in the URL.

Alternatively you can pass a URI string in place of the $_SERVER[“REQUEST_URI”] by replacing the $url variable with something else.

No need for an example on that one, as I’m sure if you’re already reading this post then you will know what to do.

If all else fails then leave a comment below..

See also  How to Generate a Random Number/String in Terraform
Notify of
1 Comment
Oldest Most Voted
Inline Feedbacks
View all comments
vps tw
vps tw
7 years ago

It’s actually a nice and helpful piece of information.
I’m satisfied that you shared this helpful information with us.
Please stay us informed like this. Thank you for sharing.

Would love your thoughts, please comment.x