Think\Db\Query::chunk PHP Method

chunk() public method

分批数据返回处理
public chunk ( integer $count, callable $callback, string $column = null ) : boolean
$count integer 每次处理的数据数量
$callback callable 处理回调方法
$column string 分批处理的字段名
return boolean
    public function chunk($count, $callback, $column = null)
    {
        $options = $this->getOptions();
        if (isset($options['table'])) {
            $table = is_array($options['table']) ? key($options['table']) : $options['table'];
        } else {
            $table = '';
        }
        $column = $column ?: $this->getPk($table);
        $bind = $this->bind;
        $resultSet = $this->limit($count)->order($column, 'asc')->select();
        while (!empty($resultSet)) {
            if (false === call_user_func($callback, $resultSet)) {
                return false;
            }
            $end = end($resultSet);
            $lastId = is_array($end) ? $end[$column] : $end->{$column};
            $resultSet = $this->options($options)->limit($count)->bind($bind)->where($column, '>', $lastId)->order($column, 'asc')->select();
        }
        return true;
    }