monkeymatrix monkeymatrix - 6 months ago 40
PHP Question

Convert a Hashmap string into an array using PHP

I am using an API which returns data as a string in the following format:

{"domain.com":{"status":"available","classkey":"domcno"}}


I want to put this result in to a multi-dimensional PHP array, but since the input is a string, I can't think of a convenient way to convert this.

Is there a function that can automatically parse this data into an array as desired?

Answer

That's JSON, simple enough:

$array = json_decode($string, true);

Yields:

Array
(
    [domain.com] => Array
        (
            [status] => available
            [classkey] => domcno
        )

)
Comments