0
我有一个应该运行如果数组不为空,但由于某些原因,它仍然会运行,即使它是空的代码的代码。这里是我有:PHP Laravel如果(!空())运行时,空
$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
是否为空,这将运行。
那么是什么_is_ $ invoiceSent? var_dump($ invoiceSent)在'!empty'检查之前应该告诉你实际上是否需要它。如果它是一个对象(如结果集),它不会被视为空的。 – MatsLindh
$ invoiceSent中有什么? empty()只满足一定数量的空标准,所以如果它是一个空键的数组,它将不会计数。阅读这里的文档:http://php.net/manual/en/function.empty.php – JonLuca