Codeigniter 如何使用for each循环在数据库中插入数组值

Codeigniter 如何使用for each循环在数据库中插入数组值,codeigniter,model,Codeigniter,Model,我有一个数组,我想使用codeigniter插入数据库中的值,我不知道如何插入,我正在尝试,但我无法得到答案 我的模型 打印$subjectHandling 现在我想在这个值中插入数据库中的值 我正在这样努力 我得到了错误**数组到字符串的转换**,那么怎么做呢。我想在数据库中插入两个ROE这应该可以 $subjectHandling['subjectId'] = array(1, 2); $reg_dat = array(); foreach($subjectHandling['subje

我有一个数组,我想使用codeigniter插入数据库中的值,我不知道如何插入,我正在尝试,但我无法得到答案

我的模型

打印$subjectHandling

现在我想在这个值中插入数据库中的值

我正在这样努力

我得到了错误**数组到字符串的转换**,那么怎么做呢。我想在数据库中插入两个ROE这应该可以

$subjectHandling['subjectId'] = array(1, 2); 

$reg_dat = array();
foreach($subjectHandling['subjectId'] as $key => $value) {
 $reg_dat[] = array('staffId'=> 1, 'subjectId' => $value);
}
$this->db->insert_batch('subject_handling', $reg_dat);
    foreach($subjectHandling as $key=>$value) {

    $reg_dat = array(
        'statffId'   => '1',
        'subjectId'      => $value,
    );
 $this->db->insert("subject_handling" , $reg_dat);

}
$subjectHandling['subjectId'] = array(1, 2); 

$reg_dat = array();
foreach($subjectHandling['subjectId'] as $key => $value) {
 $reg_dat[] = array('staffId'=> 1, 'subjectId' => $value);
}
$this->db->insert_batch('subject_handling', $reg_dat);