To check whether an array is empty, the code is as follows in PHP−
Example
<?php
$arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110");
if (empty($arr)) {
echo "Empty Array...";
}
else{
echo "Array isn't empty ...";
}
?>Output
This will produce the following output−
Array isn't empty ...
Example
Let us now see another example −
<?php
$arr = array( "p"=>"150", "q"=>"100", "r"=>"120", "s"=>"110");
if (count($arr) == 0) {
echo "Empty Array...";
}
else{
echo "Array isn't empty ...";
}
?>Output
This will produce the following output−
Array isn't empty ...