我正在尝试从数组值的起始和结尾处删除引号。我使用了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}]
答案 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);