src/xPDO/Om/xPDOObject.php
public function toArray($keyPrefix= '', $rawValues= false, $excludeLazy= false, $includeRelated= false) {
        $objArray= null;
        if (is_array($this->_fields)) {
            $keys= array_keys($this->_fields);
            if (!$excludeLazy && $this->isLazy()) {
                $this->_loadFieldData($this->_lazy);
            }
            foreach ($keys as $key) {
                if (!$excludeLazy || !$this->isLazy($key)) {
                    $objArray[$keyPrefix . $key]= $rawValues ? $this->_fields[$key] : $this->get($key);
                }
            }
        }
        if (!empty($includeRelated)) {
            $graph = null;
            if (is_int($includeRelated) && $includeRelated > 0) {
                $graph = $this->xpdo->getGraph($this->_class, $includeRelated);
            } elseif (is_string($includeRelated)) {
                $graph = $this->xpdo->fromJSON($includeRelated);
            } elseif (is_array($includeRelated)) {
                $graph = $includeRelated;
            }
            if ($includeRelated === true || is_array($graph)) {
                foreach ($this->_relatedObjects as $alias => $branch) {
                    if ($includeRelated === true || array_key_exists($alias, $graph)) {
                        if (is_array($branch)){
                            /** @var xPDOObject $obj */
                            foreach($branch as $pk => $obj){
                                $objArray[$alias][$pk] = $obj->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
                            }
                        } elseif ($branch instanceof xPDOObject) {
                            $objArray[$alias] = $branch->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
                        }
                    }
                }
            }
        }
        return $objArray;
    }
public function toArray($keyPrefix= '', $rawValues= false, $excludeLazy= false, $includeRelated= false) {
        $objArray= null;
        if (is_array($this->_fields)) {
            $keys= array_keys($this->_fields);
            if (!$excludeLazy && $this->isLazy()) {
                $this->_loadFieldData($this->_lazy);
            }
            foreach ($keys as $key) {
                if (!$excludeLazy || !$this->isLazy($key)) {
                    $objArray[$keyPrefix . $key]= $rawValues ? $this->_fields[$key] : $this->get($key);
                }
            }
        }
        if (!empty($includeRelated)) {
            $graph = null;
            if (is_int($includeRelated) && $includeRelated > 0) {
                $graph = $this->xpdo->getGraph($this->_class, $includeRelated);
            } elseif (is_string($includeRelated)) {
                $graph = $this->xpdo->fromJSON($includeRelated);
            } elseif (is_array($includeRelated)) {
                $graph = $includeRelated;
            }
            if ($includeRelated === true || is_array($graph)) {
                foreach ($this->_relatedObjects as $alias => $branch) {
                    if ($includeRelated === true || array_key_exists($alias, $graph)) {
                        if (is_array($branch)){
                            /** @var xPDOObject $obj */
                            foreach($branch as $pk => $obj){
                                $objArray[$alias][$pk] = $obj->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
                            }
                        } elseif ($branch instanceof xPDOObject) {
                            $objArray[$alias] = $branch->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
                        }
                    }
                }
            }
        }
        return $objArray;
    }
public function toArray ( $ keyPrefix = '' , $ rawValues = false , $ excludeLazy = false , $ includeRelated = false ) { $ objArray = null ; if ( is_array ( $ this -> _fields ) ) { $ keys = array_keys ( $ this -> _fields ) ; if ( ! $ excludeLazy && $ this -> isLazy ( ) ) { $ this -> _loadFieldData ( $ this -> _lazy ) ; } foreach ( $ keys as $ key ) { if ( ! $ excludeLazy || ! $ this -> isLazy ( $ key ) ) { $ objArray [ $ keyPrefix . $ key ] = $ rawValues ? $ this -> _fields [ $ key ] : $ this -> get ( $ key ) ; } } } if ( ! empty ( $ includeRelated ) ) { $ graph = null ; if ( is_int ( $ includeRelated ) && $ includeRelated > 0 ) { $ graph = $ this -> xpdo -> getGraph ( $ this -> _class , $ includeRelated ) ; } elseif ( is_string ( $ includeRelated ) ) { $ graph = $ this -> xpdo -> fromJSON ( $ includeRelated ) ; } elseif ( is_array ( $ includeRelated ) ) { $ graph = $ includeRelated ; } if ( $ includeRelated === true || is_array ( $ graph ) ) { foreach ( $ this -> _relatedObjects as $ alias => $ branch ) { if ( $ includeRelated === true || array_key_exists ( $ alias , $ graph ) ) { if ( is_array ( $ branch ) ) { /** @var xPDOObject $obj */ foreach ( $ branch as $ pk => $ obj ) { $ objArray [ $ alias ] [ $ pk ] = $ obj -> toArray ( $ keyPrefix , $ rawValues , $ excludeLazy , $ includeRelated === true ? true : $ graph [ $ alias ] ) ; } } elseif ( $ branch instanceof xPDOObject ) { $ objArray [ $ alias ] = $ branch -> toArray ( $ keyPrefix , $ rawValues , $ excludeLazy , $ includeRelated === true ? true : $ graph [ $ alias ] ) ; } } } } } return $ objArray ; }
Copies the object fields and corresponding values to an associative array.

@param string $keyPrefix An optional prefix to prepend to the field values.
@param boolean $rawValues An optional flag indicating if you want the raw values instead of
those returned by the {@link xPDOObject::get()} function.
@param boolean $excludeLazy An option flag indicating if you want to exclude lazy fields from
the resulting array; the default behavior is to include them which means the object will
query the database for the lazy fields before providing the value.
@param boolean|integer|string|array $includeRelated Describes if and how to include loaded related object fields.
As an integer all loaded related objects in the graph up to that level of depth will be included.
As a string, only loaded related objects matching the JSON graph representation will be included.
As an array, only loaded related objects matching the graph array will be included.
As boolean true, all currently loaded related objects will be included.
@return array An array representation of the object fields/values.
Copies the object fields and corresponding values to an associative array .