Object to Array

Sometimes we need to convert object to array in PHP

so here it is

enjoy

    function object_to_array($data)
    {
        if (is_array($data) || is_object($data))
        {
            $result = array();
            foreach ($data as $key => $value)
            {
                $result[$key] = object_to_array($value);
            }
            return $result;
        }
        return $data;
    }

Published by indradhi

coding + sharing = influence

3 thoughts on “Object to Array

Leave a comment