Handy bit of PHP to convert and object to an array
public function objectToArray($obj)
{
if(!is_array($obj) && !is_object($obj))
return $obj;
if(is_object($obj))
$obj = get_object_vars($obj);
return array_map(array($this, 'objectToArray'), $obj);
}