Iterate over an array of objects and group them by the value of a property

@return array[group] = class[]
424787
public function groupBy($list, $property, $meta=null)
    {
        if (!$list) {
            return [];
        }
        if (!$meta) {
            if (!($first = current($list))) {
                throw new \UnexpectedValueException();
            }
            $meta = $this->mapper->getMeta(get_class($first));
        }

        $groups = [];

        $props = $meta->getProperties();
        foreach ($list as $object) {
            $propDef = !isset($props[$property]) ? null : $props[$property];
            $value = !$propDef || !isset($propDef['getter']) 
                ? $object->{$property} 
                : call_user_func(array($object, $propDef['getter']));

            $groups[$value][] = $object;
        }
        return $groups;
    }
1137221
protected function getArray()
    {
        $key         = $this->getRangeKey()->getPropertyMetadata()->name;
        $array       = parent::getArray();
        $array[$key] = $this->getRangeValue();

        return $array;
    }
391759
public function toArray()
    {
        $aReturn = array();

        foreach (get_object_vars($this) as $sKey => $mValue) {
            if (is_object($mValue) and true === method_exists($mValue, 'toArray')) {
                $aReturn[$sKey] = $mValue->toArray();
            } else {
                $aReturn[$sKey] = $mValue;
            }
        }

        return $aReturn;
    }
775166
public function toArray()
    {
        $hydrator = new ClassMethods();
        $vars = $hydrator->extract($this);
        
        foreach ($vars as $key => &$value) {
            if ($value === null) {
                unset($vars[$key]);
            } elseif (is_object($value) && ! $value instanceof \ArrayObject) {
                if (method_exists($value, 'toArray')) {
                    $value = $value->toArray();
                    if (count($value) == 0) {
                        unset($vars[$key]);
                    }
                } elseif ($value instanceof IsNull) {
                    $vars[$key] = null;
                } elseif ($value instanceof \stdClass) {
                    $vars[$key] = new \stdClass();
                } else {
                    unset($vars[$key]);
                }
            } elseif (is_bool($value)) {
                $vars[$key] = (int) $value;
            }
        }
        
        return $vars;
    }
645457
public function getPropertiesAsArray()
    {
        $array = array();

        foreach ($this->getProperties() as $property) {
            $array[$property->getName()] = [ 'value' => $property->getValue(), 'type' => $property->getType() ];
        }

        return $array;
    }
683296
public function toArray()
    {
        $array = [];

        $array['alias']    = $this->getAlias();
        $array['property'] = $this->getProperty();
        $array['field']    = $this->getField();

        if (!empty($this->getType())) {
            $array['type'] = $this->getType();
        }

        $array['behavior'] = $this->getBehavior()->toArray();

        if (!empty($this->getFormat())) {
            $format = [];
            foreach ($this->getFormat() as $item) {
                $format[] = $item->toArray();
            }
            $array['format'] = $format;
        }

        if (!empty($this->getAllowedValues())) {
            $array['allowedValues'] = $this->getAllowedValues();
        }

        if (!empty($this->getComposition())) {
            $array['composition'] = $this->getComposition()->toArray();
        }

        if (!empty($this->getDefault())) {
            $array['default'] = $this->getDefault();
        }

        return $array;
    }
373758
public function toArray()
    {
        $reflection = new ReflectionObject($this);

        $properties = $this->propertiesToArray($reflection);
        $methods    = $this->methodsToArray($reflection);

        return array_merge($properties, $methods);
    }
1256900
def array_to_hash(array)
      case array
        when self.class
          array.to_hash
        when Array
          array.map { |element| array_to_hash(element) }
        else
          array
      end
    end
256932
public static function getGroup() {
		
		$attr = [];

		foreach(static :: $group as $group) {
			$attr = static :: arrayRecursiveMerge($attr, $group);
		}

		return $attr;
	}
835687
public function toArray() {
        $result = iterator_to_array($this);
        foreach($result as $key => &$value) {
            if($value instanceof ArrayObject) {
                $value = $value->toArray();
            }
        }

        return $result;
    }
891563
public static function toArray()
    {
        $class = get_called_class();
        if (!array_key_exists($class, self::$cache)) {
            $reflection          = new \ReflectionClass($class);
            self::$cache[$class] = $reflection->getConstants();
        }

        return self::$cache[$class];
    }
476677
@NotNull
    public Object[] toArray() {
        return toArray(new IntFunction<Object[]>() {

            @NotNull
            @Override
            public Object[] apply(int value) {
                return new Object[value];
            }
        });
    }
1035449
public function splitByClass()
    {

        $classes = array();
        foreach( $this->collection as $key => $entity ) {
            $classes[get_class($entity)][] = $key;
        }
        ksort( $classes );

        $output = array();
        foreach( $classes as $class => $splHashes ) {
            $container = $this->newContainer();
            $container->class = $class;
            $container->collection = array_intersect_key(
                $this->collection,
                array_flip( $splHashes )
            );
            $output[$class] = $container;
        }
        return $output;

    }
504983
public function toArray() {

		$class = new \ReflectionClass($this);
		$props = $class -> getProperties();
		$data  = [];

		foreach($props as $prop) {

			if($class -> name === $prop -> class) {

				if(true === isset($this -> {$prop -> name})) {
					$data[$prop -> name] = $this -> {$prop -> name};
				}
			}
		}

		foreach($this -> columns as $column) {
			$data[key($column)] = $column[key($column)];
		}

		return $data;
	}
134948
public function groupByColumns()
	{
		$data = $this->dataProvider->getData();
		if (count($data) == 0) {
			return;
		}

		if (!is_array($this->mergeColumns)) {
			$this->mergeColumns = array($this->mergeColumns);
		}
		if (!is_array($this->extraRowColumns)) {
			$this->extraRowColumns = array($this->extraRowColumns);
		}

		//store columns for group. Set object for existing columns in grid and string for attributes
		$groupColumns = array_unique(array_merge($this->mergeColumns, $this->extraRowColumns));
		foreach ($groupColumns as $key => $colName) {
			foreach ($this->columns as $column) {
				if (property_exists($column, 'name') && $column->name == $colName) {
					$groupColumns[$key] = $column;
					break;
				}
			}
		}


		//values for first row
		$lastStored = $this->getRowValues($groupColumns, $data[0], 0);
		foreach ($lastStored as $colName => $value) {
			$lastStored[$colName] = array(
				'value' => $value,
				'count' => 1,
				'index' => 0,
			);
		}

		//iterate data
		$rowcount = count($data);
		for ($i = 1; $i < $rowcount; $i++) {
			//save row values in array
			$current = $this->getRowValues($groupColumns, $data[$i], $i);

			//define is change occured. Need this extra foreach for correctly proceed extraRows
			$changedColumns = array();
			foreach ($current as $colName => $curValue) {
				if ($curValue != $lastStored[$colName]['value']) {
					$changedColumns[] = $colName;
				}
			}

			/**
			 * if this flag = true -> we will write change (to $this->_changes) for all grouping columns.
			 * It's required when change of any column from extraRowColumns occurs
			 */
			$saveChangeForAllColumns = (count(array_intersect($changedColumns, $this->extraRowColumns)) > 0);

			/**
			 * this changeOccurred related to foreach below. It is required only for mergeType == self::MERGE_NESTED,
			 * to write change for all nested columns when change of previous column occurred
			 */
			$changeOccurred = false;
			foreach ($current as $colName => $curValue) {
				//value changed
				$valueChanged = ($curValue != $lastStored[$colName]['value']);
				//change already occured in this loop and mergeType set to MERGETYPE_NESTED
				$saveChange = $valueChanged || ($changeOccurred && $this->mergeType == self::MERGE_NESTED);

				if ($saveChangeForAllColumns || $saveChange) {
					$changeOccurred = true;

					//store in class var
					$prevIndex = $lastStored[$colName]['index'];
					$this->_changes[$prevIndex]['columns'][$colName] = $lastStored[$colName];
					if (!isset($this->_changes[$prevIndex]['count'])) {
						$this->_changes[$prevIndex]['count'] = $lastStored[$colName]['count'];
					}

					//update lastStored for particular column
					$lastStored[$colName] = array(
						'value' => $curValue,
						'count' => 1,
						'index' => $i,
					);

				} else {
					$lastStored[$colName]['count']++;
				}
			}
		}

		//storing for last row
		foreach ($lastStored as $colName => $v) {
			$prevIndex = $v['index'];
			$this->_changes[$prevIndex]['columns'][$colName] = $v;

			if (!isset($this->_changes[$prevIndex]['count'])) {
				$this->_changes[$prevIndex]['count'] = $v['count'];
			}
		}
	}
1277647
public function toArray()
    {
        
        $result = $this->array;
        
        foreach ($result as $key => $val) {
            
            /**
             * @var self $val
             */
            if (is_a($val, self::class)) {
                $result[$key] = $val->toArray();
            } else {
                $result[$key] = $val;
            }
        }
        
        return $result;
    }
368638
public static function toArray()
    {
        $class = \get_called_class();
        if (!isset(static::$cache[$class])) {
            $reflection            = new \ReflectionClass($class);
            static::$cache[$class] = $reflection->getConstants();
        }
        return static::$cache[$class];
    }