gpt4 book ai didi

laravel - 错误异常 : Undefined offset: 0

转载 作者:行者123 更新时间:2023-12-04 13:34:47 27 4
gpt4 key购买 nike

在我的数组推送上,如果它们具有相同的日期,我想连接 2 个数据

$goal = Goal::where('employee_id',Auth::user()->employees->first()->id)
->with('accomplishments')->orderBy('date','asc')->get();

$next_week = $goal->whereBetween('date',[$add_start_date,$add_end_date]);
$last_week = $goal->whereBetween('date',[$sub_start_date,$sub_end_date]);

$goals = [];
$date = "";
for ($i=0; $i < count($next_week); $i++) {
if($next_week[$i]['date']==$date){
$goals[$i-1]['activity'] = $goals[$i-1]['activity'] .', '. $next_week[$i]['activity'];
continue;
}
array_push($goals,$next_week[$i]);
$date = $next_week[$i]['date'];
}

最佳答案

在 Laravel 集合上使用过滤时,索引丢失,
要重新索引结果数组,请使用“值”:

 $next_week = $goal->whereBetween('date',[$add_start_date,$add_end_date])->values();
$last_week = $goal->whereBetween('date',[$sub_start_date,$sub_end_date])->values();

关于laravel - 错误异常 : Undefined offset: 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62870674/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com