Index rows by parent id
@param array $rows
@return array
558121
protected static function indexByParent($rows)
    {
        $parents = [];

        foreach ($rows as $row) {
            $parents[(int) $row['parent_id']][(int) $row['child_id']] = (int) $row['child_id'];
        }

        return $parents;
    }
580799
public function normalizeColumns(array &$rows) : array
    {
        $maxNumColumns = 0;

        // Find the max number of columns that appear in any given row
        foreach ($rows as $row) {
            $maxNumColumns = max($maxNumColumns, count($row));
        }

        $maxLengths = array_pad([], $maxNumColumns, 0);

        // Normalize the number of columns in each row
        foreach ($rows as &$row) {
            $row = array_pad($row, $maxNumColumns, '');
        }

        // Get the length of the longest value in each column
        foreach ($rows as &$row) {
            foreach ($row as $column => &$value) {
                $value = trim($value);
                $maxLengths[$column] = max($maxLengths[$column], mb_strlen($value));
            }
        }

        return $maxLengths;
    }
339670
public function several(array $ids)
    {
        $result = [];
        foreach ($ids as $id) {
            if ($this->has($id)) {
                $result[$id] = $this->get($id);
            }
        }
        return $result;

    }
3321
public function setRows($rows = []) {

        if (!empty($this->cols)) {
            if (count($rows[0]) < 1) {
                throw new \Exception('Expected 2 dimensional array for rows');
            } elseif (count($this->cols) != 0 && count($this->cols) != count($rows[0])) {
                throw new \Exception('No of cols must equivelent to no heads in rows');
            }
        }
        $this->rows = $rows;
        return $this;
    }
1290466
public function createLocationsFromRows(array $rows, $prefix = '')
    {
        $locations = array();

        foreach ($rows as $row) {
            $id = $row[$prefix . 'node_id'];
            if (!isset($locations[$id])) {
                $locations[$id] = $this->createLocationFromRow($row, $prefix);
            }
        }

        return array_values($locations);
    }
127521
public function extractNotificationsFromRows(array $rows): array
    {
        $notifications = [];
        foreach ($rows as $row) {
            $notifications[] = $this->extractNotificationFromRow($row);
        }

        return $notifications;
    }
317888
public static function rowsToArray($rows, array $options = [])
    {
        $limit = array_get($options, 'limit', 0);
        $offset = array_get($options, 'offset', 0);

        $array = [];
        if ($offset > 0) {
            if ($limit > 0) {
                for ($i = 0; ($i < $limit && $rows->offsetExists($offset + $i)); $i++) {
                    $array[] = $rows->offsetGet($offset + $i);
                }
            } else {
                for ($i = 0; $rows->offsetExists($offset + $i); $i++) {
                    $array[] = $rows->offsetGet($offset + $i);
                }
            }
        } else {
            foreach ($rows as $row) {
                $array[] = $row;
            }
        }

        return $array;
    }
271877
public function loadCollectionValues(LoadingContext $context, array $rows) : array
    {
        $primaryKey = $this->primaryKeyColumn->getName();
        $ids        = [];

        foreach ($rows as $key => $row) {
            $ids[$key] = $row->getColumn($primaryKey);
        }

        return $ids;
    }
595837
public function many( array $ids = [] ) {
        if( count( $ids ) === 0 ) {
            return [];
        }

        $pages = array_chunk( $ids, $this->maxPageSize() );

        $requests = [];
        foreach( $pages as $page ) {
            $requests[] = [ 'ids' => implode( ',', $page ) ];
        }

        $responses = $this->requestMany( $requests );

        $result = [];
        foreach( $responses as $response ) {
            $result = array_merge( $result, $response->json() );
        }

        return $result;
    }
1261020
public function selectByIds(array $ids = array())
    {
        if (empty($ids)) {
            return array();
        }

        $ids = array_map('intval', $ids);

        $sql = $this->getSelectQueryByIds($ids);

        $resultSet = $this->db->fetchAll($sql);

        return $this->implementVOs($resultSet);
    }
660143
public function deleteRows(array $rows): array
    {
        $list = [];
        foreach ($rows as $key => $row) {
            $key = (string)$key;
            if (!$this->hasKey($key)) {
                $list[$key] = null;
            } else {
                $path = $this->getPathFromKey($key);
                $file = $this->getFile($path);
                $list[$key] = $this->deleteFile($file);

                $storage = $this->getStoragePath($key);
                $media = $this->getMediaPath($key);

                $this->deleteFolder($storage, true);
                $media && $this->deleteFolder($media, true);
            }
        }

        return $list;
    }
913120
private function sanitize(array $rows)
    {
        $_documentClass = $this->_documentClass;

        if (isset($this->_options[self::ENTRY_SANITIZE]) && $this->_options[self::ENTRY_SANITIZE]) {
            foreach ($rows as $key => $value) {

                if (is_array($value) && isset($value[$_documentClass::ENTRY_ID])) {
                    unset($rows[$key][$_documentClass::ENTRY_ID]);
                }

                if (is_array($value) && isset($value[$_documentClass::ENTRY_REV])) {
                    unset($rows[$key][$_documentClass::ENTRY_REV]);
                }
            }
        }

        return $rows;
    }
1279992
public function in($id, array $ids)
    {
        $allParents = $this->getHierarchy($id);

        /**
         * To increase the efficiency, we can index the results of the parent.
         */
        $allParentsIndexed = [];
        foreach ($allParents as $parent) {
            $allParentsIndexed[$parent->getId()] = $parent;
        }

        foreach ($ids as $possibleParentId) {
            if (isset($allParentsIndexed[$possibleParentId])) {
                return true;
            }
        }

        return false;
    }
844292
public function setRows($rows) {
		if ($rows && count($rows) > 0) {
			foreach ($rows as $row) {
				$this->setRow($row);
			}
		}

		return $this;
	}
468158
protected function enrichWithMany(array $rows)
    {
        $manyFields = $this->getManyFields();
        $idToData   = [];
        foreach ($rows as $row) {
            foreach ($manyFields as $manyField) {
                $row[$manyField] = [];
            }
            $idToData[$row['id']] = $row;
        }
        foreach ($manyFields as $manyField) {
            $this->enrichWithManyField($idToData, $manyField);
        }
        return array_values($idToData);
    }
261302
protected function groupRowDataBySuppliedColumns(array $rows) : array
    {
        $groups = [];

        foreach ($rows as $row) {
            $columnNames = array_keys($row);
            sort($columnNames, SORT_STRING);
            $key = implode('||', $columnNames);

            $groups[$key][] = $row;
        }

        return $groups;
    }
507280
public function findByIds(array $ids)
    {
        $entities = [];

        for ($i = 0; $i < count($this->registries); $i++) {
            /** @var RegistryInterface $registry */
            $registry = $this->registries[ $i ];
            $found = $registry->findByKeys($ids);
            $entities = array_merge($entities, $found);

            $this->updateRegistries($found, $i - 1);

            if (count($entities) === count($ids)) {
                break;
            }
        }

        return $entities;
    }