skip to Main Content

I want to stop the query chunk loop, is there a way to do that? My code

$limit = 1000;
$total = 0;

$query->chunkById(
    100,
    function ($items) {
        foreach ($items as $item) {
            // do something

            if ($total >= $limit) {
                // how to stop?
            }
            
            $total++;
        }
    }
);

I already followed many solutions i found in many sites but still not working.

2

Answers


  1. Chosen as BEST ANSWER

    I found the solution to my problem, just return false in the loop

    if ($total >= $limit) {
       return false;
    }
    

  2. How about the following the code?

    function ($items) use (&$total, &$limit) {
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search