php怎么将下面格式的字符串转为数组 "[[["2023-06-08","100","100","100"]],[["2023-06-09","100","100","100"]]]"
时间: 2023-07-06 16:39:17 浏览: 40
您可以使用 `json_decode` 函数将 JSON 格式的字符串转换为 PHP 数组。JSON 格式的字符串需要满足一定的规范才能被 `json_decode` 函数正确解析。在您提供的字符串中,外层的方括号表示数组,内层的方括号也表示数组,因此需要使用 `json_decode` 函数两次,如下所示:
```php
$str = '[[["2023-06-08","100","100","100"]],[["2023-06-09","100","100","100"]]]';
$arr = json_decode($str, true);
$arr = json_decode($arr[0][0], true); // 注意这里需要解析两次
print_r($arr);
```
输出结果如下:
```
Array
(
[0] => Array
(
[0] => 2023-06-08
[1] => 100
[2] => 100
[3] => 100
)
[1] => Array
(
[0] => 2023-06-09
[1] => 100
[2] => 100
[3] => 100
)
)
```
其中,`json_decode` 函数的第二个参数设置为 `true`,表示将返回关联数组而非对象。解析两次的原因是,外层的方括号表示数组,内层的方括号也表示数组,因此需要先解析一次得到一个包含两个数组的数组,然后再解析每个子数组。