反向PHP。$ .param

There is a function in jQuery, $.param, that takes an object (can be a nested object too) and converts it to a string suitable for GET usage.

I was wondering if there is a PHP function that would take that string and convert it back to an array (or nested array, if that was the case). Is there such a function?

EDIT:

I'm sending this JS object (after $.param()-ing it):

{"categories": [90000]}

I'm reading it on the server side from $_GET and then I'm passing it to parse_str.

I also have a test code that recreates the expected PHP array.

The entire thing looks like:

$filter = $_GET["my_array"];
parse_str($filters, $_filters);
error_log(print_r($_filters, true), 4);
$x = [
    "categories" => [
        90000
    ]
];
error_log(print_r($x, true), 4);

The output of that code is:

(
    [categories] => Array
        (
            [0] => 90000
        ) 
)


(
    [categories] => Array
        (
            [0] => 90000
        ) 
)

So I assume they are identical. But then I'm passing that array to Yii's findAll method and it's working only with $x.

Maybe parse_str is mixing plain arrays and associative arrays when parsing and that is why findAll is not working?

I think you may be looking for parse_url or parse_str that Jon Stirling mentioned.

Bear in mind that all the query parameters will already exist in the $_GET global.

Usage for the query part of the URL.

var_dump(parse_url($url, PHP_URL_QUERY));

Yes, you can use parse_str:

$serializedData = $_GET['data'];
$unserializedData = array();

parse_str($serializedData, $unserializedData);

print_r($unserializedData);