Convert 2-d array to object in PHP
<?php
/**
* convert 2-d array to object
*/
$tempObject = new stdClass();
foreach ($results as $k => $row) {
$tempObject->{$k} = (object) $row;
}
/**
* Converts an N-d array to object recursively.
*
* @param array $array
*
* @return \stdClass
*/
function toObject(array $array)
{
$object = new stdClass();
foreach ($array as $k => $row) {
$object->{$k} = is_array($row) ? toObject($row) : $row;
}
return $object;
}