array($checkuser) will wrap the $checuser variable in an array.
isset(...) returns true if the variable exists and is not null
reference: https://www.php.net/manual/en/function.isset.php
So the condition if(isset($userrole)) will always evaluate to true.
I guess you might be after this:
$checkuser = getUser();
if(! empty($checkuser)) {
$userrole = explode(",", $checkuser->GetMultiRole);
} else {
$userrole = array();
// or using the short-array syntax
// $userrole = [];
}
empty() will return true when a variable is empty. To understand what conditions the empty(...) function considers a variable to be empty, please read this reference:
https://www.php.net/manual/en/function.empty.php
As you are using Laravel (you marked the post in the Laravel category) you could use the filled(...) helper, which will check if the variable is "filled" with a value:
$checkuser = getUser();
if(filled($checkuser)) {
$userrole = explode(",", $checkuser->GetMultiRole);
} else {
$userrole = [];
}