src/Collection.php
public static function toArray($data, $options = [])
    {
        $defaults = ['key' => true, 'handlers' => []];
        $options += $defaults;
        $result = [];

        foreach ($data as $key => $item) {
            switch (true) {
                case is_array($item):
                    $result[$key] = static::toArray($item, $options);
                break;
                case (!is_object($item)):
                    $result[$key] = $item;
                break;
                case (isset($options['handlers'][$class = get_class($item)])):
                    $result[$key] = $options['handlers'][$class]($item);
                break;
                case ($item instanceof static):
                    $result[$key] = static::toArray($item, $options);
                break;
                case (method_exists($item, '__toString')):
                    $result[$key] = (string) $item;
                break;
                default:
                    $result[$key] = $item;
                break;
            }
        }
        return $options['key'] ? $result : array_values($result);
    }
public static function toArray($data, $options = [])
    {
        $defaults = ['key' => true, 'handlers' => []];
        $options += $defaults;
        $result = [];

        foreach ($data as $key => $item) {
            switch (true) {
                case is_array($item):
                    $result[$key] = static::toArray($item, $options);
                break;
                case (!is_object($item)):
                    $result[$key] = $item;
                break;
                case (isset($options['handlers'][$class = get_class($item)])):
                    $result[$key] = $options['handlers'][$class]($item);
                break;
                case ($item instanceof static):
                    $result[$key] = static::toArray($item, $options);
                break;
                case (method_exists($item, '__toString')):
                    $result[$key] = (string) $item;
                break;
                default:
                    $result[$key] = $item;
                break;
            }
        }
        return $options['key'] ? $result : array_values($result);
    }
public static function toArray ( $ data , $ options = [ ] ) { $ defaults = [ 'key' => true , 'handlers' => [ ] ] ; $ options += $ defaults ; $ result = [ ] ; foreach ( $ data as $ key => $ item ) { switch ( true ) { case is_array ( $ item ) : $ result [ $ key ] = static :: toArray ( $ item , $ options ) ; break ; case ( ! is_object ( $ item ) ) : $ result [ $ key ] = $ item ; break ; case ( isset ( $ options [ 'handlers' ] [ $ class = get_class ( $ item ) ] ) ) : $ result [ $ key ] = $ options [ 'handlers' ] [ $ class ] ( $ item ) ; break ; case ( $ item instanceof static ) : $ result [ $ key ] = static :: toArray ( $ item , $ options ) ; break ; case ( method_exists ( $ item , '__toString' ) ) : $ result [ $ key ] = ( string ) $ item ; break ; default : $ result [ $ key ] = $ item ; break ; } } return $ options [ 'key' ] ? $ result : array_values ( $ result ) ; }
Exports a `Collection` instance to an array.

@param  mixed $data    Either a `Collection` instance, or an array representing a
`Collection`'s internal state.
@param  array $options Options used when converting `$data` to an array:
- `'key'`      _boolean_: A boolean indicating if keys must be conserved or not.
- `'handlers'` _array_  : An array where the keys are fully-namespaced class
names, and the values are closures that take an instance of the class as a
parameter, and return an array or scalar value that the instance represents.
@return array          The value of `$data` as a pure PHP array, recursively converting all
sub-objects and other values to their closest array or scalar equivalents.
Exports a Collection instance to an array .