- json_encode: documentation ( source)
<?php
class Test implements \JsonSerializable {
protected $a;
protected $b;
public $c;
public function __construct() {
$this->a = 1;
$this->b = 2;
$this->c = 3;
}
public function jsonSerialize() {
return [$this->a, $this->c, $this->b];
}
}
$t = new Test();
echo json_encode($t->jsonSerialize());
echo json_encode($t);