php - insert batch from array 2 dimension codeigniter -
i wanto insert , insert batch 1 form 2 tables , post data have contain array 2 dimension, , result print_r post data
array ( [foo] => blalala [bar] => xxxxxx [date] => 2014-06-30 [time] => 08:34:30 [fruit] => array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) [car] => array ( [0] => 2 [1] => 3 [2] => 5 [3] => 7 ) [food] => array ( [0] => 2 [1] => 3 ) [drink] => array ( [0] => 3 ) [snack] => array ( [0] => 2 ) )
and result want
$array_master = array( [foo] => blalala, [bar] => xxxxxx, [date] => 2014-06-30, [time] => 08:34:30, );
and next array count data 2nd dimension array [fruit],[food],[car],[drink],[snack]
[0] => array ( [agenda_terkait_type] => **(if [fruit] ==1,[food] ==2,[car] ==3,[drink] ==4,[snack] ==5)** [agenda_terkait_agenda_id] => [agenda_terkait_data_id] => (value of [fruit],[food],[car],[drink],[snack]) [agenda_terkait_status] => 1 ) [1] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [2] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [3] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [4] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [5] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [6] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [7] => array ( [agenda_terkait_type] => [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [8] => array ( [agenda_terkait_type] => 1 [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [9] => array ( [agenda_terkait_type] => 1 [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [10] => array ( [agenda_terkait_type] => 2 [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 ) [11] => array ( [agenda_terkait_type] => 2 [agenda_terkait_agenda_id] => 121 [agenda_terkait_data_id] => [agenda_terkait_status] => 1 )
thank's help. i'll appreciate. , sorry english :)
you can use foreach loops this: try this:
$original_values = array( 'foo' => 'blalala', 'bar' => 'xxxxxx', 'date' => '2014-06-30', 'time' => '08:34:30', 'fruit' => array(1, 2, 3, 4), 'car' => array(2, 3, 5, 7), 'food' => array(2, 3), 'drink' => array(3), 'snack' => array(2), ); $array_master = array(); foreach ($original_values $key => $value) { if(!is_array($value)) { $array_master[$key] = $value; unset($original_values[$key]); } } $batch = array(); foreach($original_values $key => $value) { foreach ($value $element) { $type = ''; switch($key) { case 'fruit': $type = 1; break; case 'car': $type = 2; break; case 'food': $type = 3; break; case 'drink': $type = 4; break; case 'snack': $type = 5; break; } $batch[] = array( 'agenda_terkait_type' => $type, 'agenda_terkait_agenda_id' => '', 'agenda_terkait_data_id' => $element, 'agenda_terkait_status' => 1, ); } } echo '<pre>'; print_r($array_master); print_r($batch);
it outputs this:
array ( [foo] => blalala [bar] => xxxxxx [date] => 2014-06-30 [time] => 08:34:30 ) array ( [0] => array ( [agenda_terkait_type] => 1 [agenda_terkait_agenda_id] => [agenda_terkait_data_id] => 1 [agenda_terkait_status] => 1 ) [1] => array ( [agenda_terkait_type] => 1 [agenda_terkait_agenda_id] => [agenda_terkait_data_id] => 2 [agenda_terkait_status] => 1 ) [2] => array ( [agenda_terkait_type] => 1 [agenda_terkait_agenda_id] => [agenda_terkait_data_id] => 3 [agenda_terkait_status] => 1 ) [3] => array ( [agenda_terkait_type] => 1 [agenda_terkait_agenda_id] => [agenda_terkait_data_id] => 4 [agenda_terkait_status] => 1 ) .. continued
Comments
Post a Comment