Kevin
Woblick

CollectionsArticlesNewsTestsTutorials

Convert arrays to objects in various ways

1 min. read

TIL: You can convert arrays to objects in various ways:

$obj = (object) $array;
$obj = json_decode(json_encode($array));
$object = new stdClass();
foreach ($array as $key => $value) {
    $object->$key = $value;
}

Webmentions

0 Mentions
0 Reposts
Likes