Fastest way to Convert Associative Arrays to Objects

Simply cast an Associative array:

1
2
3
4
5
$obj = (object) array('animal' => 'dog', 'name' => 'simon');

// Then you can access values as objects:
echo $obj->animal; // Outputs dog
echo $obj->name; // Outputs simon

No need to create a class or Function to accomplish it.



Do you need help with a project? or have a new project in mind that you need help with?

Contact Me