【发布时间】:2019-07-12 15:59:51
【问题描述】:
问题是,我的数组代码没有得到预期的结果。
我尝试过array_merge,但它所做的只是合并所有数组。
$medicine_order = $request['medicine_id'];
array:3 [▼
0 => "25"
1 => "32"
2 => "30"
]
$medicine_quantity = $request['medicine_quantity'];
array:3 [▼
0 => "3"
1 => "10"
2 => "6"
]
$count = 0;
foreach ($medicine_order as $id) {
$item = new Historyitem;
$item->medicine_id = $id;
foreach ($medicine_quantity as $id2) {
$item->historyitem_quantity = $id2;
}
$item->save();
$count++;
}
我想将这些值存储在我的数据库中。
array:3 [▼
0 => "25"
1 => "3"
]
array:3 [▼
0 => "32"
1 => "10"
]
array:3 [▼
0 => "30"
1 => "6"
]
但是我得到了这些值:
array:3 [▼
0 => "25"
1 => "6"
]
array:3 [▼
0 => "32"
1 => "6"
]
array:3 [▼
0 => "30"
1 => "6"
]
【问题讨论】:
-
我不知道我们能做到这一点@FedericoklezCulloca 我不得不尝试解决这个问题,而且效果很好! 3v4l.org/6PTgI
标签: php arrays laravel-5.4