我想知道变量是否是一个集合.
我不能使用is_object(),因为即使它不是集合也是如此.现在我使用它,它的工作原理:
if(is_object($images) && get_class($images) != 'Illuminate\Database\Eloquent\Collection') {
Run Code Online (Sandbox Code Playgroud)
但我觉得这太丑了,我花时间问你另一种解决方案.
你有什么主意吗?
有没有办法检查对象是否是一个SimpleXMLELement?
private function output_roles($role) {
foreach ($role as $current_role) {
$role_ = $current_role->attributes();
$role_type = (string) $role_->role;
echo "<tr>";
echo "<td><b>" . $role_type . "</b></td>";
echo "</tr>";
$roles = $role->xpath('//role[@role="Administrator"]//role[not(role)]');
if (is_array($roles)) {
$this->output_roles($roles);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的功能,$role->xpath只有在提供的对象是a时才可以SimpleXMLElement.任何人?
我怎么知道什么类的类是PHP中的变量:
if($var == \Collection)
echo "congratulations";
?>
Run Code Online (Sandbox Code Playgroud)