xxxxxxxxxx
// Suppose we have an array
$array = array();
// Method 1: Using empty() function
if (empty($array)) {
echo "Array is empty";
} else {
echo "Array is not empty";
}
// Method 2: Using count() function
if (count($array) == 0) {
echo "Array is empty";
} else {
echo "Array is not empty";
}
xxxxxxxxxx
$arr = array();
if(!empty($arr)){
echo "not empty";
}
else
{
echo "empty";
}
xxxxxxxxxx
// Declare an array and initialize it
$non_empty_array = array('apples' => '2');
// Declare an empty array
$empty_array = array();
// Condition to check array is empty or not
if(!empty($non_empty_array)) {
echo "Given Array is not empty <br>";
}
if(empty($empty_array)) {
echo "Given Array is empty";
}
xxxxxxxxxx
// Check if array is empty using empty() function
$array = [];
if (empty($array)) {
echo "Array is empty";
} else {
echo "Array is not empty";
}
xxxxxxxxxx
unset($foo); // $foo is gone
$foo = array(); // $foo is here again