{"id":1922,"date":"2023-11-20T11:53:19","date_gmt":"2023-11-20T17:53:19","guid":{"rendered":"https:\/\/blog.ls-al.com\/?p=1922"},"modified":"2023-11-20T11:53:19","modified_gmt":"2023-11-20T17:53:19","slug":"php-stdclass-object-vs-array","status":"publish","type":"post","link":"https:\/\/blog.ls-al.com\/php-stdclass-object-vs-array\/","title":{"rendered":"php stdClass Object vs Array"},"content":{"rendered":"

Sometimes you may prefer handling your data like an object instead of an array. I prefer object style when I am working with code handling json from API's etc..<\/p>\n

So instead of the $my_array["field1"] notation you can handle it as $my_array->field1.<\/p>\n

Its pretyy simple just cast your array variable like this:<\/p>\n

$data = (object) $my_array;<\/code><\/pre>\n

Better write up here:
\nhttps:\/\/www.webmaster-source.com\/2009\/08\/20\/php-stdclass-storing-data-object-instead-array\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

Sometimes you may prefer handling your data like an object instead of an array. I prefer object style when I<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1922","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1922","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/comments?post=1922"}],"version-history":[{"count":1,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1922\/revisions"}],"predecessor-version":[{"id":1923,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/posts\/1922\/revisions\/1923"}],"wp:attachment":[{"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/media?parent=1922"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/categories?post=1922"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ls-al.com\/wp-json\/wp\/v2\/tags?post=1922"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}