How to Check Array Empty or Not in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Merge Two Arrays with Unique Values in PHP?
- How to Merge Two Array in PHP?
- How to Remove Numeric Keys in PHP Array?
- How to Remove String Values in PHP Array?
- How to Remove Numeric Values in PHP Array?
- How to Get First 2 Elements of Array in PHP?
- How to Get Last 5 Elements of Array in PHP?
- How to Get Random Value from an Array in PHP?
- How to Get First Element of Array in PHP?
- How to Add Prefix in Each Key of PHP Array?
- How to Get Minimum Key Value of Array in PHP?
- How to Remove Null Values from Array in PHP?