Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 请告诉我为什么将空数组写入变量_Php_Mysql_Laravel_Web - Fatal编程技术网

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

Php 请告诉我为什么将空数组写入变量,php,mysql,laravel,web,Php,Mysql,Laravel,Web,如果$January中没有数据,则无论数据可用性如何,都会将空数组写入$January。告诉我如何修复它,以及为什么会发生这种情况?以前也有类似的答案 您需要在$articles上使用clone,如下所示: $January = $articles->whereMonth('updated_at','01') ->whereYear('updated_at', $year) ->get(); $February = $articles->whereMonth('

如果
$January
中没有数据,则无论数据可用性如何,都会将空数组写入
$January
。告诉我如何修复它,以及为什么会发生这种情况?

以前也有类似的答案

您需要在
$articles
上使用
clone
,如下所示:

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

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

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