How to check whether an array is empty using PHP?

Posted by LaravelIndia - 1 year ago

Using empty() Function: This function determines whether a given variable is empty. This function does not return a warning if a variable does not exist. Syntax:

bool empty( $var )

<?php 

// Declare an array and initialize it 
$non_empty_array = array('URL' => 'https://www.pakainfo.com/'); 

// 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"; 
?>