note 103137 added to function.json-encode

From: Date: Mon, 28 Mar 2011 16:35:31 +0000
Subject: note 103137 added to function.json-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-178266@lists.php.net to get a copy of this message
As json_encode() is recursive, you can use it to serialize whole structure of objects. class A { public $a = 1; public $b = 2; public $collection = array(); function __construct(){ for ( $i=3; $i-->0;){ array_push($this->collection, new B); } } } class B { public $a = 1; public $b = 2; } echo json_encode(new A); Will give: { "a":1, "b":2, "collection":[{ "a":1, "b":2 },{ "a":1, "b":2 },{ "a":1, "b":2 }] } ---- Server IP: 93.93.89.9 Probable Submitter: 91.103.66.177 ---- Manual Page -- http://www.php.net/manual/en/function.json-encode.php Edit -- https://master.php.net/note/edit/103137 Del: integrated -- https://master.php.net/note/delete/103137/integrated Del: useless -- https://master.php.net/note/delete/103137/useless Del: bad code -- https://master.php.net/note/delete/103137/bad+code Del: spam -- https://master.php.net/note/delete/103137/spam Del: non-english -- https://master.php.net/note/delete/103137/non-english Del: in docs -- https://master.php.net/note/delete/103137/in+docs Del: other reasons-- https://master.php.net/note/delete/103137 Reject -- https://master.php.net/note/reject/103137 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178266) next »