4 回答
TA贡献1853条经验 获得超18个赞
$id = 1;
$isTemplate = true;
$address = "address, \n tel. 1234455";
$array = [
'results' => [
[
'id' => $id,
'isTemplate' => $isTemplate,
'text' => $address,
],
],
];
$result = json_encode($array);
TA贡献1810条经验 获得超4个赞
尝试这个
您只需要再添加 1 个嵌套。
$resultArray = ['results' => [['id'=> 1, 'isTemplate' => true, 'text'=> '<span class="d-block option-head">\n nazwa\n</span>\n<span class="d-none"> - </span>\n<span class="d-block option-sub">\n address,\n tel. 1234455\n </span>']]];
echo '<pre>';
print_r(json_encode($resultArray));
exit;
TA贡献2019条经验 获得超9个赞
您的代码缺少嵌套级别。
$resultArray = array('results' => [
['id' => 1, 'isTemplate' => true, 'text' => '<span class="d-block option-head">\n nazwa\n</span>\n<span class="d-none"> - </span>\n<span class="d-block option-sub">\n address,\n tel. 1234455\n </span>']
]);
var_dump($resultArray, json_encode($resultArray));
TA贡献1871条经验 获得超13个赞
$id = 1;
$isTemplate = true;
$address = "address, \n tel. 1234455";
$text= '<span class="d-block option-head">\n nazwa\n</span>\n<span class="d-none"> - </span>\n<span class="d-block option-sub">\n address,\n';
$array[] = ['id'=>$id ,'isTemplate'=>$isTemplate, 'address' => $address,'text'=>$text];
$value = json_encode($array);
$value 将保存所需的结果......
- 4 回答
- 0 关注
- 173 浏览
添加回答
举报