#til

#TIL : Transform array to object shorthand

To transform a array to stdClass in PHP, try to cast type using (object) before the array variable.

$arr = ['a' => 1, 'b' => 5];
$obj = (object) $arr;
echo $obj->b;

Enjoyed this post?

If you found this helpful, consider sharing it or leaving a kudo!

0 kudos