数组中的数组

问题描述 投票:0回答:1

我想以这种格式在数组中插入数据。

day1[
  screen1 [  ]
  screen2 [  ]
]
day1[
   screen1 [  ]
   screen2 [  ]
]

到目前为止我已经尝试过。

  for($i=0;$i<7;$i++){
        $date = Carbon::now()->addDays($i)->format('Y-m-d');
        $a = strtotime($date);
        $days[]=date('l',$a);
        $screen = screen::pluck('id')->toArray();
        for($j=0;$j<count($screen);$j++){
             $showTime[] =ScheduledMovie::Where('movie_id',$id)->Where('show_date',$date)->Where('show_day',$days[$i])->where('screen_id',$screen[$j])->pluck('show_time_start')->toArray();
        }
    }

使用的表有schedule_table、Movie_table、screen_table。电影表和时间表表具有一对多关系。我的目标是从时间表中提取特定屏幕的特定日期的显示时间。到目前为止,我能够提取特定日期的演出时间。

php laravel
1个回答
2
投票
$dayScreenArr = [];
for($i=0;$i<7;$i++){
    $date = Carbon::now()->addDays($i)->format('Y-m-d');
    $a = strtotime($date);
    $days[]=date('l',$a);
    $dayScreenArr[$i]['day'.$i][] = $days;
    $screen = screen::pluck('id')->toArray();
    for($j=0;$j<count($screen);$j++){
         $showTime[] =ScheduledMovie::Where('movie_id',$id)->Where('show_date',$date)->Where('show_day',$days[$i])->where('screen_id',$screen[$j])->pluck('show_time_start')->toArray();
         $dayScreenArr[$i]['day'.$i]['screen'.$i][] = $showTime;
    }
}
/* check this */
echo "<pre>";
print_r($dayScreenArr);
© www.soinside.com 2019 - 2024. All rights reserved.