Issue
$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;
The output looks like this
{"toemail":"abc@gmail.com","agentname":"john","agentid":"110012","subject":"The details of total number of properties saved by your clients","totalprop":"131"}
But what changes should i have make, so that the output looks like this
{"toemail":"abc@gmail.com",
"agentname":"john",
"agentid":"110012",
"subject":"The details of total number of properties saved by your clients",
"totalprop":"131"}
Solution
Use JSON_PRETTY_PRINT
and also need to use echo "<pre>"
;
From PHP Manual: Use whitespace in returned data to format it. Available since PHP 5.4.0
$array = array(
'test'=>1,
'test2'=>'test',
'test3'=>'test 3'
);
echo "<pre>";
echo json_encode($array,JSON_PRETTY_PRINT);
Result:
{
"test": 1,
"test2": "test",
"test3": "test 3"
}
Answered By - devpro Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.