Monday, December 9, 2013

Convert an object to an array with php

<?php



    /**
    *
    * Convert an object to an array
    *
    * @param    object  $object The object to convert
    * @reeturn      array
    *
    */



    function objectToArray( $object )
    {
        if( !is_object( $object ) && !is_array( $object ) )
        {
            return $object;
        }
        if( is_object( $object ) )
        {
            $object = get_object_vars( $object );
        }
        return array_map( 'objectToArray', $object );
    }


    /*** convert the array to object ***/

 //    $array = objectToArray( $obj );

    /*** show the array ***/



  //  print_r( $array );




?>

No comments:

Post a Comment