$batch = [];
$batchSize = 1000;
foreach($bigArray as $position => $item) {
if(count($batch) === $batchSize) {
$memoryUsage = memory_get_usage();
//do something
$batch = [];
} else {
$batch[$position] = $item;
}
}
if($ids) {
$sql = 'delete from `rus` where `idvol` not in('.implode(', ', $ids).')';
mysql_query($sql);
}