Convert Query String to an Array
Problem Statement:
Convert the query string pg_id=2&parent_id=2&document&video into an array. The expected output is:
array( 'pg_id' => 2, 'parent_id' => 2, 'document' => '', 'video' => '' )
Solution Using parse_str:
The parse_str function allows you to parse a query string and assign the values to variables. To store the data in an array instead of variables, set the second parameter to TRUE.
$queryString = "pg_id=2&parent_id=2&document&video"; parse_str($queryString, $queryArray, TRUE); print_r($queryArray);
The above is the detailed content of How to Convert a Query String to an Array in PHP?. For more information, please follow other related articles on the PHP Chinese website!