• 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
retrieving and showing data

#11
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.

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 )
Reply


Messages In This Thread
retrieving and showing data - by davy_yg - 07-12-2016, 07:34 AM
RE: retrieving and showing data - by arma7x - 07-12-2016, 07:44 AM
RE: retrieving and showing data - by davy_yg - 07-12-2016, 07:53 AM
RE: retrieving and showing data - by arma7x - 07-12-2016, 08:09 AM
RE: retrieving and showing data - by mwhitney - 07-12-2016, 08:26 AM
RE: retrieving and showing data - by rtenny - 07-12-2016, 09:18 AM
RE: retrieving and showing data - by davy_yg - 07-12-2016, 09:30 PM
RE: retrieving and showing data - by rtenny - 07-13-2016, 09:19 AM
RE: retrieving and showing data - by InsiteFX - 07-12-2016, 07:10 PM
RE: retrieving and showing data - by InsiteFX - 07-13-2016, 07:42 AM
RE: retrieving and showing data - by InsiteFX - 07-13-2016, 10:14 AM
RE: retrieving and showing data - by davy_yg - 07-13-2016, 06:31 PM
RE: retrieving and showing data - by davy_yg - 07-13-2016, 06:36 PM
RE: retrieving and showing data - by InsiteFX - 07-14-2016, 03:08 AM
RE: retrieving and showing data - by arma7x - 07-14-2016, 03:46 AM
RE: retrieving and showing data - by Ivo Miranda - 07-14-2016, 04:13 AM
RE: retrieving and showing data - by davy_yg - 07-16-2016, 07:18 PM
RE: retrieving and showing data - by mwhitney - 07-18-2016, 01:56 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.