I have created a query in codegniter for updating data in the form of array when I am update the the data with 3 fields it's working fine but when i try to add 4th field and then I try to update data it says undefined offset 3 | undefined offset 4 don't know why is this happening
public function update_content() {
    $i = 0;
    foreach($this->input->post() as $val):
        $heading = $this->input->post('heading')[$i];
        $span    = $this->input->post('span')[$i];
        $id      = $this->input->post('id')[$i];
        $type    = $this->input->post('type')[$i];
        $data = array(
            'heading' => $heading,
            'span'    => $span,
            'type'    => $type
        );
        $this->db->where('id', $id);
        $this->db->update('contentpage', $data);
        $i++;
    endforeach;
}
Here is my html
<input type="text" name="heading[]" size="20" value="<?php echo $data->heading; ?>" />
<input type="text" name="span[]" size="20" value="<?php echo $data->span; ?>" />
<input type="hidden" name="id[]" size="20" value="<?php echo $data->id; ?>" />
<input type="hidden" name="type[]" value="Default" />
 
     
     
    