Copy Cdbcriteria To Variable

Hi, I need to delete records from db by chunks using CDbCriteria. I do it this way

$criteria->select = '';

$chank_num = 5;

$criteria->limit = $chank_num;


    $update_ids = array();

    $res = $model->findAll($criteria);

    if(!empty($res)) foreach ($res AS $item){

        $update_ids[] = $item->id;



        $temp_criteria = $criteria;

        $temp_criteria->addInCondition('id', $update_ids);

        $res = $model->deleteAll($temp_criteria);

        $total_cnt += count($update_ids);


}while(count($update_ids) == $chank_num);

But the problem is that for the first time loop goes well and deletes 5 records but the second time $criteria has additional condition (id IN array of ids found in first loop). It looks like addInCondition affects not only $temp_criteria but $criteria too. Can anybody give me a hint whats going wrong?

Use the clone keyword to make a copy of an object:

$temp_criteria = clone $criteria;

Thanks, nineinchnick. It did the job.