I'm trying to pass a multi dimensional array to a database table and columns, but im getting stuck in a place that i cannot understand how can i put the foreach function to get the correct result.
Below my data:
data:
array(5) {
["option_id"]=> int(115)
["name"]=>
array(3) {
[0]=> string(1) "S"
[1]=> string(1) "M"
[2]=> string(1) "L"
}
["value"]=> array(3) {
[0]=> string(5) "12345"
[1]=> string(5) "12346"
[2]=> string(5) "12347"
}
["price"]=> array(3) {
[0]=> string(3) "199"
[1]=> string(3) "199"
[2]=> string(3) "199"
}
["inventory"]=> array(3) {
[0]=> string(1) "1"
[1]=> string(1) "1"
[2]=> string(1) "1"
}
}
each string from name, value, price, inventory need to be saved in each row in database

but my problem is that on create the foreach to store the data in database it store only the name on all columns.
The model im using to save the data is:
function saveBatchOptionsValues($option_values){
$sequence = 0;
foreach($option_values['name'] as $value){
$values['option_id'] = $option_values['option_id'];
$values['name'] = $value['name'];
$values['value'] = $value['value'];
$values['sequence'] = $sequence;
$values['inventory'] = $value['inventory'];
$values['weight'] = floatval(1.00);
$values['price'] = floatval($value['price']);
$sequence++;
$this->db->insert('option_values', $values);
}
}
The question is how can i pass the columns value, price, inventory etc.. to each row?
Any help is appreciated !