{"id":11,"date":"2009-05-15T22:38:56","date_gmt":"2009-05-15T17:08:56","guid":{"rendered":"http:\/\/vikku.info\/codesnippets\/?p=11"},"modified":"2009-05-15T22:48:49","modified_gmt":"2009-05-15T17:18:49","slug":"object-to-array","status":"publish","type":"post","link":"http:\/\/vikku.info\/codesnippets\/php\/object-to-array\/","title":{"rendered":"object to array"},"content":{"rendered":"<p>I used xmlhttp request to send multiple data from javascript to php. I created objects and properties (virtually it is referred as Associative Array in javascript). And finally\u00a0 all the objects are encapsulated into a main object and this was stringified by using JSON method&#8230; finally i got a json string which i sent using xmlhttp.<\/p>\n<p>When i received the string in php and debugged it and is said all as StdObjects and when i tried to use in foreach it didnt work. So i searched for the following and i converted the StdObject to array using the following. Hope people might use it.<\/p>\n<p>If anybody willing to comment on its performance or any other idea then please do so&#8230;<\/p>\n<pre lang=\"php\">\r\n\r\nfunction object_to_array($data) \r\n{\r\n  if(is_array($data) || is_object($data))\r\n  {\r\n    $result = array(); \r\n    foreach($data as $key => $value)\r\n    { \r\n      $result[$key] = object_to_array($value); \r\n    }\r\n    return $result;\r\n  }\r\n  return $data;\r\n}\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I used xmlhttp request to send multiple data from javascript to php. I created objects and properties (virtually it is referred as Associative Array in javascript). And finally\u00a0 all the objects are encapsulated into a main object and this was stringified by using JSON method&#8230; finally i got a json string which i sent using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/11"}],"collection":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/comments?post=11"}],"version-history":[{"count":5,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/11\/revisions"}],"predecessor-version":[{"id":16,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/posts\/11\/revisions\/16"}],"wp:attachment":[{"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/media?parent=11"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/categories?post=11"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/vikku.info\/codesnippets\/wp-json\/wp\/v2\/tags?post=11"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}