[英]How do i traverse through multidimensional array in laravel 5.2
我正在尝试从多个表中获取以下表结构的数据
表的内容是
在上述情况下,我只想为city_id = 1获取唯一的movie_id数组,而我的代码如下
$movies=General_cities::with('cinemahall.showtime')->where('city_id',$selectedcity->city_id)->get();
return $movies[0]['cinemahall'][1]['showtime'][0]['movie_id'];
$ selectedcity-> city_id为“ 1”的地方,我从上面的代码中获取了所有数据。 我还可以显示单个movie_id,但是我想遍历所有多维数组并收集所有唯一的movie_id。
请帮我,因为这似乎很难做到。 在上述情况下,我应该将movie_id数组设置为[1,2]。
尝试在模型中使用此功能
public function unique_movie_id()
{
return $this->join('movies_cinemahall', 'movies_cinemahall.city_id','=','general_cities.id')->join('movies_showtime', 'movies_showtime.cinema_id','=','movies_cinemahall.cinema_id')->join('movies','movies.movie_id','=','movies_showtime.movie_id')->distinct('movies.movie_id')->select('movies.id')->get();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.