<?php
class Foo implements JsonSerializable {
private $data = 'Bar';
public function jsonSerialize() {
return array('data'=>$this->data);
}
}
echo json_encode(new Foo); // Outputs: {"data":"Bar"}
<?php
$a = array(1,2,3,array(4,5,6));
echo json_encode($a,JSON_PRETTY_PRINT);
[
1,
2,
3,
[
4,
5,
6
]
]