php stdClass Object vs Array

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..

So instead of the $my_array["field1"] notation you can handle it as $my_array->field1.

Its pretyy simple just cast your array variable like this:

$data = (object) $my_array;

Better write up here: https://www.webmaster-source.com/2009/08/20/php-stdclass-storing-data-object-instead-array/

Next Post Previous Post