{"id":39,"date":"2013-04-09T22:26:12","date_gmt":"2013-04-09T14:26:12","guid":{"rendered":"http:\/\/www.zyuns.com\/?p=39"},"modified":"2015-02-15T20:51:34","modified_gmt":"2015-02-15T12:51:34","slug":"stdclass-e5-92-8c-array-e4-ba-92-e6-8d-a2","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=39","title":{"rendered":"stdClass \u548c Array \u4e92\u6362"},"content":{"rendered":"<p>http:\/\/justcoding.iteye.com\/blog\/1551349<\/p>\n<pre class=\"lang:default decode:true crayon-selected\">\n&lt;?php\n\nfunction objectToArray($d) {\nif (is_object($d)) {\n\/\/ Gets the properties of the given object\n\/\/ with get_object_vars function\n$d = get_object_vars($d);\n}\n\nif (is_array($d)) {\n\/*\n* Return array converted to object\n* Using __FUNCTION__ (Magic constant)\n* for recursive call\n*\/\nreturn array_map(__FUNCTION__, $d);\n}\nelse {\n\/\/ Return array\nreturn $d;\n}\n}\n\nfunction arrayToObject($d) {\nif (is_array($d)) {\n\/*\n* Return array converted to object\n* Using __FUNCTION__ (Magic constant)\n* for recursive call\n*\/\nreturn (object) array_map(__FUNCTION__, $d);\n}\nelse {\n\/\/ Return object\nreturn $d;\n}\n}\n\n\/\/ Create new stdClass Object\n$init = new stdClass;\n\n\/\/ Add some test data\n$init-&gt;foo = \"Test data\";\n$init-&gt;bar = new stdClass;\n$init-&gt;bar-&gt;baaz = \"Testing\";\n$init-&gt;bar-&gt;fooz = new stdClass;\n$init-&gt;bar-&gt;fooz-&gt;baz = \"Testing again\";\n$init-&gt;foox = \"Just test\";\n\n\/\/ Convert array to object and then object back to array\n$array = objectToArray($init);\n$object = arrayToObject($array);\n\n\/\/ Print objects and array\nprint_r($init);\necho \"n\";\nprint_r($array);\necho \"n\";\nprint_r($object);\n\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/justcoding.iteye.com\/blog\/1551349 &lt;?php funct [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-39","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/39","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=39"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions"}],"predecessor-version":[{"id":452,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions\/452"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}