I have $result variable which can be array or null. If it's not empty array I'd say it's true and if it's null, I'd say it's false.
I'm thinking of several ways like
#1
$array = array (
$res => is_null($result)
);
#2
$array = array (
$res => $result !== null? true : false,
);
But I'm not so confident for both ways. Do you have better recommendation?
I think you are looking for the empty function. From the docs:
The following values are considered to be empty:
You don’t say that your variable could hold these other values potentially so I’ll assume it can’t. This means you can simply check !empty($result)
.
For instance:
function v($r){
return !empty($r);
}
assert(false === v(null));
assert(false === v([]));
assert(true === v([1]));