Laravel:找出变量是否为集合 [英] Laravel: find out if variable is collection
本文介绍了Laravel:找出变量是否为集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想确定变量是否为集合.
I want to find out if a variable is a collection.
我不能使用is_object(),因为即使它不是一个集合,它也将是真实的. 现在,我使用它,它的工作原理是:
I can't use is_object() because it will be true even if it is not an collection. For now I use this, and it works:
if(is_object($images) && get_class($images) != 'Illuminate\Database\Eloquent\Collection') {
但是我认为这很丑陋,我花时间询问您其他解决方案.
But I think it's so ugly that I spend time asking you about another solution.
你有什么主意吗?
推荐答案
您不能使用
if(is_a($images, 'Illuminate\Database\Eloquent\Collection')) {
....do whatever for a collection....
} else {
....do whatever for not a collection....
}
或
if ($images instanceof Illuminate\Database\Eloquent\Collection) {
}
这篇关于Laravel:找出变量是否为集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文