4 回答

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超18個(gè)贊
$id = 1;
$isTemplate = true;
$address = "address, \n tel. 1234455";
$array = [
'results' => [
[
'id' => $id,
'isTemplate' => $isTemplate,
'text' => $address,
],
],
];
$result = json_encode($array);

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試這個(gè)
您只需要再添加 1 個(gè)嵌套。
$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貢獻(xiàn)2019條經(jīng)驗(yàn) 獲得超9個(gè)贊
您的代碼缺少嵌套級(jí)別。
$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貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
$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 將保存所需的結(jié)果......
- 4 回答
- 0 關(guān)注
- 220 瀏覽
添加回答
舉報(bào)