To check if a Set is empty in PHP, you can use the empty()
function or check the size of the Set using the count()
function.
In this example,
$set
and initialize it with some elements, or an empty Set if there are no elements.empty()
function to check if the Set $set
is empty.empty()
function returns true
; otherwise, it returns false
.<?php
$set = new Set(); // Or new Set(['a', 'b', 'c']) for a non-empty Set
$isEmpty = empty($set);
if ($isEmpty) {
echo 'The Set is empty';
} else {
echo 'The Set is not empty';
}
?>
The Set is empty
In this example,
$set
and initialize it with some elements, or an empty Set if there are no elements.count()
function to get the number of elements in the Set $set
.<?php
$set = new Set(); // Or new Set(['a', 'b', 'c']) for a non-empty Set
$isEmpty = count($set) === 0;
if ($isEmpty) {
echo 'The Set is empty';
} else {
echo 'The Set is not empty';
}
?>
The Set is empty
In this tutorial, we learned How to check if a Set is Empty in PHP language with well detailed examples.