Sometimes, we want to parse query string into an array with PHP.
In this article, we’ll look at how to parse query string into an array with PHP.
How to parse query string into an array with PHP?
To parse query string into an array with PHP, we can use the parse_str
function.
For instance, we write
$get_string = "pg_id=2&parent_id=2&document&video";
parse_str($get_string, $get_array);
print_r($get_array);
to call parse_str
to parse the $get_string
into the $get_array
array.
$get_array
is an associative array with the keys and values of each query parameter.
Conclusion
To parse query string into an array with PHP, we can use the parse_str
function.