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

时间:2017-07-15 19:12:44

标签: php

我有一个代码,如果一个数组不是空的话应该运行但由于某种原因,它仍然会运行,即使它是空的。这就是我所拥有的:

$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
}

无论$invoiceSent是否为空,都会运行。

1 个答案:

答案 0 :(得分:0)

get()方法返回Collection Countable

这导致empty实际上是真的,而count()将返回0.这是违反直觉的,但仍然是语言特定的功能。