【发布时间】:2021-06-27 04:26:54
【问题描述】:
$users = DB::table('users')->count();
//dd($users);
for($i=0; $i<$users ; $i++){
$updated=DB::table('users')->where('latehours' , 0)->update(['latehours'=>$total_hours[$i]]);
$updated=DB::table('users')->where('fine' , 0)->update(['fine'=>$fine[$i]]);
}
我有一个名为 users 的表,我想分别更新它的两列 latehour 和 fine,两列都在更新,但数组索引的第一个值,但我的循环不起作用。
数组是 $total_hours 和 $fine。 提前致谢
【问题讨论】:
-
你能分享你的数组值吗?
-
array:3 [▼ 0 => 1 1 => 2 2 => 3 ] 它是 $total_hours 数组
-
array:3 [▼ 0 => 100 1 => 200 2 => 300 ] 它是 $fine 数组
-
这是你当前代码的预期结果,你想做什么??
-
我想在用户 'id' 2 和 3 处拥有两个数组的数组索引 1 和索引 2 值
标签: mysql arrays laravel for-loop indexing