07-13-2016, 10:14 AM
Then that's his error he is trying to assign an object to an array
Here are to function to handle objects and arrays to convert to each other.
Here are to function to handle objects and arrays to convert to each other.
PHP Code:
if ( ! function_exists('array_to_object'))
{
/**
* array_to_object ()
* --------------------------------------------------------------------
*
* Converts an array to an object.
*
* @param $data
* @return object
*/
function array_to_object($data)
{
if (is_array($data))
{
/**
* Return array converted to object Using __FUNCTION__
* (Magic constant) for recursive call
*/
return (object) array_map(__FUNCTION__, $data);
}
else
{
return $data;
}
}
}
if ( ! function_exists('object_to_array'))
{
/**
* object_to_array ()
* --------------------------------------------------------------------
*
* Converts an object to an array.
*
* USAGE: $array = object_to_array($object);
*
* @param $obj
* @return array
*/
function object_to_array($obj)
{
if (is_object($obj))
{
// Gets the properties of the given object with get_object_vars function
$obj = get_object_vars($obj);
}
if (is_array($obj))
{
/**
* Return array converted to object Using __FUNCTION__
* (Magic constant) for recursive call
*/
return array_map(__FUNCTION__, $obj);
}
else
{
return $obj;
}
}
}
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )