2
$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"}
K L P
  • 107
  • 6
  • i mean i want the output with a new line in each object,not everything in one line. – K L P Feb 29 '16 at 07:40
  • 2
    if its just for output styling purposes, just use `JSON_PRETTY_PRINT` flag. its already in the [manual](http://php.net/manual/en/function.json-encode.php) – Kevin Feb 29 '16 at 07:40

1 Answers1

3

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"
}
devpro
  • 16,184
  • 3
  • 27
  • 38