1. 首页
  2. 编程语言

PHP json_encode() 序列化对象、数组、空对象、空数组

$result = [
    "object" => ["a" => 1],
    "array" => [1,2,3,4,5],
    "empty_object0" => new stdClass(),
    "empty_object1" => new ArrayObject(),
    "empty_object2" => (object)[],
    "empty_array" => [],
    "array_object" => [
        ["a" => 1],
        ["b" => 2]
    ]
];
echo json_encode($result);

结果:

{
    "object":{"a":1},
    "array":[1,2,3,4,5],
    "empty_object0":{},
    "empty_object1":{},
    "empty_object2":{},
    "empty_array":[],
    "array_object":[{"a":1},{"b":2}]

本文来自投稿,不代表程序员编程网立场,如若转载,请注明出处:http://www.cxybcw.com/189234.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code