Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Mohammad Amin Chitgarha MAChitgarha

🏠
Working from home
Block or report user

Report or block MAChitgarha

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@MAChitgarha
MAChitgarha / array-to-object-recursively.php
Last active Jan 6, 2019
Recursively cast a PHP array to object
View array-to-object-recursively.php
<?php
// Convert an array to object recursively, even the indexed arrays.
$object = json_decode(json_encode($array, JSON_FORCE_OBJECT));
// As simple as is!
// Note: If you skip JSON_FORCE_OBJECT constant, indexed arrays (if present) won't convert to objects and remain as indexed arrays.
You can’t perform that action at this time.