I have a multi dimensional array that have a structure like this
[nmbr] => Array
(
[0] => u
[1] => t
)
[jmlh] => Array
(
[0] => 4
[1] => 6
)
and I want to insert it into a database that will be looked like
id nmbr jmlh
1 u 4
2 t 6
i try using a for loop but it only detect the first array, the second one is not inserted into the database.
this is my for looping
$namabarang = $_POST['nmbr'];
$jumlah = $_POST['jmlh'];
for ( $i = 0; $i<$total; $i++)
{
$nmbr = $namabarang[$i];
$jmlh = $jumlah[$i];
$data = array(
'id_tender' => $primary_key,
'nmbr' => $nmbr,
'jumlah' => $jmlh
);
$this->db->insert('tb_tender_barang', $data);
}
$total?$total = (count($namabarang) > count($jumlah)) ? count($namabarang) : count($jumlah);before the for loop. This is equivalent to saying if$namabaranghas more elements then $jumlah then set $total to equal the amount of items in$namabarangelse set item count from$jumlahforeach