I have an array with approximately 50 keys & values. I would like to take the array and create class properties from the values like so:
$arr = array();
$arr['name'] = 'John';
$arr['age'] = '20';
$object = (object) $arr;
echo $object->name;
My question is, is this very resource-intensive? Would it require a lot of overhead with a large array? If so, would there be a better way of doing this?
Also, this does not work if the array is setup like:
$arr = array();
$arr['name']['boy'] = 'John';
$arr['name']['girl'] = 'Jane';
$arr['age']['boy'] = '20';
$arr['age']['girl'] = '30';
$object = (object) $arr;
echo $object->name->boy;