I’ve written a simple function that turns an array into an object. It works recursivly, so this:
Array {
[0] => "Jamie",
['hello'] => "World",
['hi'] => Array { [0] => "Another Array" }
}
Becomes this:
Object {
[0] = "Jamie",
['hello'] = "World",
['hi'] = Object { [0] = "Another Array" }
}
It’s pretty simple!
The function is here:
public function objectify($array)
{
(object)$object = "";
foreach( $array as $key => $value )
{
if ( ! is_array( $value ) )
{
$object->$key = $value;
}
else
{
$object->$key = $this->objectify($value);
}
}
return $object;
}
Cheers!
