Q:

Slicing big array: Cannot use a scalar value as an array

I'm creating a batch procedure that deletes lots of unnecesary data from database periodically.
For performance reasons I'm not using any ORM, I just:

get primary keys of selected records from db in one query, and
delete them in next query.

The problem is that there are sometimes literally milions of records to delete. So I want to delete them in parts of 1000 keys per query (delete from foo where id in(...)).
I tried this:
$chunkSize = 1000;

$ids = $mapper->getIdsForFoo(); //getting ids from db

    $idsCount = count($ids);
    if($idsCount && $ids != false){

      $chunks = ceil($idsCount / $chunkSize); //calculating chunks quantity      
      $chunksArr = array();

      //if there's more than 1000 ids, split them
      if($chunks > 1){
        for($i = 0; $i <= $chunks; $i++){
          $currentOffset = $i * $chunkSize;
          $chunks[] = \array_slice($idsCount, $currentOffset, $chunkSize);
        }
      }
      else{
        $chunksArr[] = $ids;
      }

      //deleting ids code here
    }

Unfortunately result I get is 
PHP Warning:  Cannot use a scalar value as an array
First I thought that's because of multiplication I made in array_slice()
$chunks[] = \array_slice($ids, $i * $chunkSize, $chunkSize);

But I extracted it to separate variable
$currentOffset = $i * $chunkSize;
$chunks[] = \array_slice($ids, $currentOffset, $chunkSize);

But I still get the same error.

A:

Why not use array_chunk? It does exactly what you want to do:
$chunks = array_chunk($ids, 1000);

If you don't want this solution, your given example does not declare $mailsIds. On top it is called $ids

