Spot\Entity\Collection::toArray PHP Method

toArray() public method

Return an array representation of the Collection.
public toArray ( mixed $keyColumn = null, mixed $valueColumn = null ) : array
$keyColumn mixed
$valueColumn mixed
return array If $keyColumn and $valueColumn are not set, or are both null then this will return the array of entity objects
    public function toArray($keyColumn = null, $valueColumn = null)
    {
        // Both empty
        if (null === $keyColumn && null === $valueColumn) {
            $return = array();
            foreach ($this->_results as $row) {
                $return[] = $row->toArray();
            }
            // Key column name
        } elseif (null !== $keyColumn && null === $valueColumn) {
            $return = array();
            foreach ($this->_results as $row) {
                $return[] = $row->{$keyColumn};
            }
            // Both key and valud columns filled in
        } else {
            $return = array();
            foreach ($this->_results as $row) {
                $return[$row->{$keyColumn}] = $row->{$valueColumn};
            }
        }
        return $return;
    }

Usage Example

Example #1
0
 /**
  * Set identity values from given collection
  *
  * @param \Spot\Entity\Collection
  */
 public function identityValuesFromCollection(Collection $collection)
 {
     $this->identityValue($collection->toArray($this->localKey()));
 }