如何在数组中生成一行 space
How to produce a line space in arrays
$arr = array(
'toemail'=>$v->agent_primary_email,
'agentname'=>$v->agent_firstname,
'agentid'=>$v->agent_id,
'subject'=>'The details of total number of properties saved by your clients',
'totalprop'=>$v->prop_count
);
echo json_encode($arr);exit;
输出看起来像这样
{"toemail":"abc@gmail.com","agentname":"john","agentid":"110012","subject":"The details of total number of properties saved by your clients","totalprop":"131"}
但是我应该进行哪些更改才能使输出看起来像这样
{"toemail":"abc@gmail.com",
"agentname":"john",
"agentid":"110012",
"subject":"The details of total number of properties saved by your clients",
"totalprop":"131"}
使用JSON_PRETTY_PRINT
还需要使用echo "<pre>"
;
From PHP Manual: 在返回的数据中使用空格对其进行格式化。自 PHP 5.4.0
起可用
$array = array(
'test'=>1,
'test2'=>'test',
'test3'=>'test 3'
);
echo "<pre>";
echo json_encode($array,JSON_PRETTY_PRINT);
结果:
{
"test": 1,
"test2": "test",
"test3": "test 3"
}
$arr = array(
'toemail'=>$v->agent_primary_email,
'agentname'=>$v->agent_firstname,
'agentid'=>$v->agent_id,
'subject'=>'The details of total number of properties saved by your clients',
'totalprop'=>$v->prop_count
);
echo json_encode($arr);exit;
输出看起来像这样
{"toemail":"abc@gmail.com","agentname":"john","agentid":"110012","subject":"The details of total number of properties saved by your clients","totalprop":"131"}
但是我应该进行哪些更改才能使输出看起来像这样
{"toemail":"abc@gmail.com",
"agentname":"john",
"agentid":"110012",
"subject":"The details of total number of properties saved by your clients",
"totalprop":"131"}
使用JSON_PRETTY_PRINT
还需要使用echo "<pre>"
;
From PHP Manual: 在返回的数据中使用空格对其进行格式化。自 PHP 5.4.0
起可用$array = array(
'test'=>1,
'test2'=>'test',
'test3'=>'test 3'
);
echo "<pre>";
echo json_encode($array,JSON_PRETTY_PRINT);
结果:
{
"test": 1,
"test2": "test",
"test3": "test 3"
}