How to Check Array Empty or Not in PHP?

By Hardik Savani May 14, 2024 Category : PHP

Hey Developer,

I am going to explain to you example of check if array is empty php. you can see how to check array empty or not in php. you can see php check if array is empty. This example will help you php array check empty or not. Here, Create a basic example of check array value empty or not in php.

we will use empty() function and count() function to check an array is empty or not in php. so, let's see the simple code of how to check array is empty or not in php.

Example 1:

index.php

<?php

$array = [];

if (empty($array)) {

echo('The array is empty.');

} else {

echo('The array is not empty.');

}

?>

Output:

The array is empty.

Example 2:

index.php

<?php

$array = [];

if (count($array) === 0) {

echo('The array is empty.');

} else {

echo('The array is not empty.');

}

?>

Output:

The array is empty.

I hope it can help you...

Tags :
Shares