php 数组字符串,如果转为数组

各位童鞋,这种数组字符串如何转为数组。。。

$arr=array (
  'address' => '["河北省","秦皇岛市","海港区"]',
);
如何将 字符串转为一个数组

// array("河北省","秦皇岛市","海港区")

 

$arr=array ( 'address' => '["河北省","秦皇岛市","海港区"]', );

$addr = json_decode($arr['address']);
print_r($addr);

现在最傻的办法。

        $addr=  '["河北省","秦皇岛市","海港区"]';
        $addr=str_replace("[","", $addr);
        $addr=str_replace("]","", $addr);
        $addr=str_replace("\"","", $addr);
        $addr= explode(",", $addr);
        dump($addr);

json_decode 啊。。php有对应的json操作函数

字符串转json对象

https://www.php.net/manual/zh/function.json-decode.php

 

json对象转字符串

https://www.php.net/manual/zh/function.json-encode.php