Helper method to convert db records to instances.

@param array $arr of subscriptions.

@return array of subscriptions as instances.
516414
protected static function get_instances($arr) {
        $result = array();
        foreach ($arr as $key => $sub) {
            $result[$key] = new subscription($sub);
        }
        return $result;
    }
163841
final public static function instantiate (array $record)
	{
		$className 	= get_called_class();
		$object 	= new $className;
		foreach ($record as $attribute => $value):
			$object->$attribute = $value;
		endforeach;
		return $object;
	}
531057
static function array2object(array $arr, $class = 'StdClass')
    {
        $obj = new $class;
        foreach ($arr as $key => $value) {
            $obj->{$key} = is_array($value) ? static::array2object($value, $class) : $value;
        }
        return $obj;
    }
718346
final public function update(array $arr)
    {
        if (!$this->pdo) {
            throw  new Exception('您还没有连接数据库', Exception::CODE_DATABASE_ERROR);
        }
        //修改
        $sql = "update " . $this->getTable() . " set ";
        $sets = [];
        foreach ($arr as $key => $val) {
            $sets[] = $this->formatColumn($key) . ' = :' . $key;
        }
        $sql .= implode(',', $sets);
        $sql .= $this->buildWhere();
        $this->sql = $sql;
        /**
         * 只获取sql
         */
        if ($this->justSql) {
            return true;
        }
        $sth = $this->pdo->prepare($sql);
        $ret = $sth->execute($arr);
        $this->lastQueryAt = time();
        $this->resetCon();
        return $ret ? $sth->rowCount() : $ret;
    }
306555
public static function fromItems(Traversable $arr, callable $cb = null)
    {
        // We can only do it this way if we can count it
        if ($arr instanceof Countable) {
            $sfa = new SplFixedArray(count($arr));
            foreach ($arr as $i => $el) {
                // Apply a mapping function if available
                if ($cb) $sfa[$i] = $cb($el, $i);
                else $sfa[$i] = $el;
            }

            return new static($sfa);
        }

        // If we can't count it, it's simplest to iterate into an array first
        $asArray = iterator_to_array($arr);
        if ($cb) {
          return static::fromArray(array_map($cb, $asArray, array_keys($asArray)));
        }
        return static::fromArray($asArray);
    }
595907
public static function mode($arr)
    {
        $vals = array_count_values($arr);
        asort($vals);
        return end(array_keys($vals));
    }
493917
protected function arrayMapRecursive($callback, $arr)
    {
        if (!is_array($arr)) {
            return call_user_func($callback, $arr);
        }
        $mapped = array();
        foreach ($arr as $k => $v) {
            $mapped[$k] = is_array($v)?
                          $this->arrayMapRecursive($callback, $v):
                          call_user_func($callback, $v);
        }
        return $mapped;
    }
326976
protected function prepareTree(array $arr) {
        $tree = [];
        foreach ($arr as $a) {
            $name = $a->getName();
            $cur = &$tree;
            foreach (explode("-", $name) as $e) {
                if (empty($cur[$e])) $cur[$e] = [];
                $cur = &$cur[$e];
            }
        }
        return $tree;
    }
1035319
public function upsert(array $arr_entities)
    {
        $obj_request = $this->setupCommit();
        $obj_mutation = $obj_request->mutableDeprecatedMutation();
        $arr_auto_id_required = [];
        foreach($arr_entities as $obj_gds_entity) {
            if(null === $obj_gds_entity->getKeyId() && null === $obj_gds_entity->getKeyName()) {
                $obj_entity = $obj_mutation->addInsertAutoId();
                $arr_auto_id_required[] = $obj_gds_entity; // maintain reference to the array of requested auto-ids
            } else {
                $obj_entity = $obj_mutation->addUpsert();
            }
            $this->applyNamespace($obj_entity->mutableKey());
            $this->determineMapper($obj_gds_entity)->mapToGoogle($obj_gds_entity, $obj_entity);
        }
        $this->execute('Commit', $obj_request, new CommitResponse());
        return $arr_auto_id_required;
    }
121514
public static function remove_empty($arr)
    {
        if (empty($arr)) {
            return null;
        }
        foreach ($arr as $key => $value) {
            if (is_array($value)) {
                $arr[$key] = self::remove_empty($value);
            } else {
                if (empty($value)) {
                    unset($arr[$key]);
                } else {
                    $arr[$key] = $value;
                }
            }
        }
        return $arr;
    }
777342
public function transformRecordsToObjects($records)
    {
        if ($this->recordClass) {
            $recordClass = $this->recordClass;
            foreach ($records as &$record) {
                $record = (new $recordClass($record));
            }
        }

        return $records;
    }
78316
public function fillByArray(array $arr): self {
        $count  = 0;
        foreach (static::defaults(true) as $key => $default) {
            isset($arr[$count]) && $this->set($key, $arr[$count]);
            $count++;
        }
        return $this;
    }
164962
function arrayClone(arr) {
        var clone = new Array(arr.length);

        this._forEach(arr, function (el, i) {
            clone[i] = el;
        });

        return clone;
    }
1068652
protected function map(array $record)
    {
        $mapping = $this->getMapping();

        if (count($mapping) > 0) {
            $result = [];

            foreach ($mapping as $columnId => $data) {
                if (!empty($data[0])) {
                    if (!isset($result[$data[0]])) {
                        $result[$data[0]] = [];
                    }
                    $result[$data[0]][$data[1]] = $record[$columnId];
                } else {
                    $result[$data[1]] = $record[$columnId];
                }
            }

            return $result;
        } else {
            return $record;
        }
    }
320901
public static function flatten(array $arr)
    {
        $flattened = [];

        array_walk_recursive($arr, function ($a) use (&$flattened) {
            $flattened[] = $a;
        });

        return $flattened;
    }
609692
protected function transform_db_records_to_entities(array $records) {
        $preprocessors = $this->get_preprocessors();
        $result = array_map(function($record) {
            return ['record' => $record];
        }, $records);

        $result = array_reduce(array_keys($preprocessors), function($carry, $preprocessor) use ($records, $preprocessors) {
            $step = $preprocessors[$preprocessor];
            $dependencies = $step->execute($records);

            foreach ($dependencies as $index => $dependency) {
                // Add the new dependency to the list.
                $carry[$index] = array_merge($carry[$index], [$preprocessor => $dependency]);
            }

            return $carry;
        }, $result);

        return $this->from_db_records($result);
    }
8620
protected static function isArrayObject($arr)
    {
        foreach(array_keys($arr) as $key) {
            if (!is_int($key)) {
                return true;
            }
        }

        return false;
    }