Convert a Hashmap string into an array using PHP

2020-02-15 09:06发布

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?

2条回答
疯言疯语
2楼-- · 2020-02-15 09:24
$j = '{"domain.com":{"status":"available","classkey":"domcno"}}';
$d = json_decode($j,true);

print_r($d);
查看更多
\"骚年 ilove
3楼-- · 2020-02-15 09:34

That's JSON, simple enough:

$array = json_decode($string, true);

Yields:

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

)
查看更多
登录 后发表回答