til

#TIL : Transform array to object shorthand

I learned on 2023-12-08 about php, web

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?

Leave a kudo — it means a lot.

0