请告诉我为什么将空数组写入变量

时间:2018-10-28 08:18:12

标签: php mysql laravel web

$January = $articles->whereMonth('updated_at','01')
  ->whereYear('updated_at', $year)
  ->get();

$February = $articles->whereMonth('updated_at','02')
  ->whereYear('updated_at', $year)
  ->get();

如果$January中没有数据,则将空数组写入$February,而不考虑数据的可用性。告诉我如何解决它,为什么会这样?

1 个答案:

答案 0 :(得分:0)

之前有类似的question回答

您需要像这样在clone上使用$articles

$January = (clone $articles)->whereMonth('updated_at','01')
  ->whereYear('updated_at', $year)
  ->get();

$February = (clone $articles)->whereMonth('updated_at','02')
  ->whereYear('updated_at', $year)
  ->get();