src/Query/SelectQuery.php
public function runChunks(int $limit, callable $callback)
    {
        $count = $this->count();

        //To keep original query untouched
        $select = clone $this;
        $select->limit($limit);

        $offset = 0;
        while ($offset + $limit <= $count) {
            $result = call_user_func_array(
                $callback,
                [$select->offset($offset)->getIterator(), $offset, $count]
            );

            if ($result === false) {
                //Stop iteration
                return;
            }

            $offset += $limit;
        }
    }
public function runChunks(int $limit, callable $callback)
    {
        $count = $this->count();

        //To keep original query untouched
        $select = clone $this;
        $select->limit($limit);

        $offset = 0;
        while ($offset + $limit <= $count) {
            $result = call_user_func_array(
                $callback,
                [$select->offset($offset)->getIterator(), $offset, $count]
            );

            if ($result === false) {
                //Stop iteration
                return;
            }

            $offset += $limit;
        }
    }
public function runChunks ( int $ limit , callable $ callback ) { $ count = $ this -> count ( ) ; //To keep original query untouched $ select = clone $ this ; $ select -> limit ( $ limit ) ; $ offset = 0 ; while ( $ offset + $ limit <= $ count ) { $ result = call_user_func_array ( $ callback , [ $ select -> offset ( $ offset ) -> getIterator ( ) , $ offset , $ count ] ) ; if ( $ result === false ) { //Stop iteration return ; } $ offset += $ limit ; } }
Iterate thought result using smaller data chinks with defined size and walk function.

Example:
$select->chunked(100, function(PDOResult $result, $offset, $count) {
dump($result);
});

You must return FALSE from walk function to stop chunking.

@param int      $limit
@param callable $callback
Iterate thought result using smaller data chinks with defined size and walk function .