删除数组值引用

时间:2019-02-18 20:22:07

标签: php

我正在尝试从数组值的起始和结尾处删除引号。我使用了str_replace但没有用。实际上我听不懂。

我的代码

foreach ($freq as $index =>  $chartData) {
    $data = implode (',', $chartData);
    $chartArray  [] = array (
        "name" => $index,
        "data" => $data
    );

}

return json_encode($chartArray);

返回

 series:[{"name":"failed","data":"0,0,0,0,0,0,0,0,0,0,0,0"}] 

但是我需要像

 series:[{"name":"failed","data":0,0,0,0,0,0,0,0,0,0,0,0}]

1 个答案:

答案 0 :(得分:3)

我认为您实际上正在寻找的东西是这样的

series:[{"name":"failed","data":[0,0,0,0,0,0,0,0,0,0,0,0]}]

只需删除implode行,然后将$chartData数组直接传递到json_encode

foreach ($freq as $index =>  $chartData) {
    $chartArray  [] = array (
        "name" => $index,
        "data" => $chartData
    );

}

return json_encode($chartArray);