Use type casting for create stdClass objects in PHP. Its convert simple array into a stdClass object. This is very quick and easy way to creating new stdClass objects with desired properties set.
Example to Create stdClass Objects in PHP
You must declare type cast objects before the array definition. check below PHP example to create stdClass object:
If you need to create stdClass object for associative array the use this code example:
Another case if you are going to use two array indexes with same key. Of course this is not allow to do, but what PHP do, Its just overwrites the property value the last key value in the array. Check the case below.
See ‘x’ key value overwrite with the last same key value. So this happen when you trying to use two array indexes with same key.
Here it is, quick and easy way to create stdclass object with desired properties value. Use this and share with others, Thanks