<?php
function p($arr) {
echo '<pre>';
print_r($arr);
echo '</pre>';
}
class test implements JsonSerializable
{
private $data = [];
public function __construct($data = []) {
$this->data = $data;
}
public function __toString() {
return json_encode($this->data , JSON_UNESCAPED_UNICODE);
}
public function jsonSerialize() {
return $this->data;
}
}
$data = [
'aa' => 'this is aa',
'bb' => 'this is bb',
'cc' => 'this is cc',
'dd' => 'this is dd',
'ee' => 'this is ee',
];
$test = new test($data);
echo json_encode($test);
很神奇的东西.原来只是一个知识点的缺失...没事确实应该翻翻手册了.