To check if a Set is not empty in PHP, you can use the count function or check if the Set is not evaluated as empty.
In this example,
mySet
containing elements of a specific type.count
function to get the number of elements in the set.<?php
// Define non-empty set
$mySet = ['apple', 'banana', 'orange'];
// Check if set is not empty using count function
if (count($mySet) > 0) {
echo 'Set is not empty';
} else {
echo 'Set is empty';
}
?>
Set is not empty
In this example,
mySet
containing elements of a specific type.<?php
// Define non-empty set
$mySet = ['apple', 'banana', 'orange'];
// Check if set is not empty using Boolean evaluation
if ($mySet) {
echo 'Set is not empty';
} else {
echo 'Set is empty';
}
?>
Set is not empty
In this tutorial, we learned How to check if a Set is Not Empty in PHP language with well detailed examples.