PHP Laravel如果(!empty())在空时运行代码

PHP Laravel如果(!empty())在空时运行代码,php,Php,我有一个应该在数组不为空时运行的代码,但由于某种原因,即使数组为空,它也会运行。以下是我所拥有的: $fifteenDays = Carbon::today('America/Los_Angeles')->subDays(15); $invoiceSent = Invoice::whereDate('invoiceDue', '<=',$fifteenDays)->where('isPaid', 0)->where('isPaying', 0)->get(); i

我有一个应该在数组不为空时运行的代码,但由于某种原因,即使数组为空,它也会运行。以下是我所拥有的:

$fifteenDays = Carbon::today('America/Los_Angeles')->subDays(15);
$invoiceSent = Invoice::whereDate('invoiceDue', '<=',$fifteenDays)->where('isPaid', 0)->where('isPaying', 0)->get();

if (!empty($invoiceSent)) {
   //Run Code In here
}
$fifteenDays=Carbon::today('America/Los_Angeles')->subDays(15);
$invoiceSent=Invoice::whereDate('invoiceDue'),“方法重新运行一个
集合,它是一个
可计数的


这会导致
empty
实际为true,而
count()
将返回0。这是违反直觉的,但仍然是一个特定于语言的功能。

那么$invoiceSent是什么呢?
var\u dump($invoiceSent)
之前!empty
检查应该告诉您实际需要它。如果它是对象(例如resultset)它不会被认为是空的。$invoiceSent中有什么?empty()只满足一定数量的空条件,因此如果它是一个包含键为空的数组,它将不计数。请阅读此处的文档:谢谢,我更改了以查看计数是否大于0,并且它对我有效。