PHP JSON_encode output

This is my first time using PHP and I am making a script that will output text in JSON format. However I am encountering problems with the formatting.

Can someone explain why my browser renders the following code as..

"1", 'b' => "2", ), array( 'a' => "1", 'b' => "2", 'c' => "3", ) ) ); ?>

instead of something like this?

[ 
  [ { "a" : "1" }, { "b" : "2" } ],
  [ { "a" : "1" }, { "b" : "2" }, { "c" : "3" } ]
]

Code:

<body>
<?php

echo json_encode(
   array( 
      array( 
         'a' => "1", 
         'b' => "2"
      ), 
      array( 
         'a' => "1", 
         'b' => "2", 
         'c' => "3"
      )
   )
);

?>
</body>


Source: json

Leave a Reply