Я хочу вставить несколько элементов из массива в базу данных с foreach
.Я получаю ошибку Message: Undefined offset
.Может кто-нибудь помочь мне выяснить, что его вызывает?
ошибка:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Line Number: 127
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Line Number: 128
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Line Number: 129
php:
<?php
$guide_input = $this->input->post('guide');
$airline_input = $this->input->post('airline');
$name_r_input = $this->input->post('name_r');
$units_input = $this->input->post('units');
$price_change_input = $this->input->post('price_change');
$guide = array();
$airline = array();
$date_go = array();
$date_back = array();
$residence = array();
foreach ($guide_input as $idx => $name) {
$guide[] = array(
'name_guide' => $guide_input[$idx], //Line Number: 121
);
$airline[] = array(
'name_airline' => $airline_input[$idx], //Line Number: 124
);
$residence[] = array(
'name_r' => $name_r_input[$idx], //Line Number: 127
'units' => $units_input[$idx], //Line Number: 128
'price_change' => $price_change_input[$idx], //Line Number: 128
);
};
$data = array(
'json1' => json_encode($residence),
'json2' => json_encode($airline),
'json3' => json_encode($guide),
);
$this->db->insert(tableName, $data);