How to check array is empty or not in php?

Today, We want to share with you check array is empty or not in php.In this post we will show you PHP empty() Function, hear for Different ways of checking if an array is empty or not in PHP we will give you demo and example for implement.In this post, we will learn about checking array empty php with an example.

How to check whether an array is empty using PHP?


 empty ($var);
    empty ($array);
if (empty($playerlist)) {
     // list is empty.

PHP code:

Using empty() Function:

Example 1:

$product_list_arr = array(); 

	echo "Given Product Array is not empty 
"; if(empty($product_list_arr)) echo "Given Product Array is empty"; ?>

Using the ‘empty’ function

$empty_arr = array();
   echo "The array is non-empty 
"; if(empty($empty_arr)) echo "The array is empty!"; ?>

Using count Function

Example 2:


Using sizeof() function

Example 3:


I hope you get an idea about how to check whether a given array in an empty array or not in PHP?.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment