Is there any similar PHP function that can unserialize to an object instead of always to an array?
$session_data = unserialize($tmp[0]); // I need this to be an object
I need to unserialize to an object so I can access values like $session_data->FirstName
instead of $session_data['FirstName']
.
EDIT: I have a function that will do this, but to me it seems sloppy and I was wondering if there was a way of doing this natively within PHP:
function ato($array) {
$obj= new stdClass();
foreach ($array as $k=> $v) {
if (is_array($v)) {
$v = array_to_object($v);
}
$obj->{strtolower($k)} = $v;
}
return $obj;
}