
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
How to check whether an array is empty using PHP?
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 ...
- Related Articles
- How to check an array is empty or not using jQuery?
- How to check whether an array is a subset of another array using JavaScript?
- How to check whether a pandas DataFrame is empty?
- How to check if an object is empty using JavaScript?
- Swift Program to Check if an array is empty
- How to check whether an array is a true array in JavaScript?
- How to Check if an Array is Empty or Not in Java
- C# program to check whether a list is empty or not
- Python program to check whether a list is empty or not?
- How to check if the file is empty using PowerShell?
- What is the preferred method to check for an empty array in NumPy?
- How to check for multidimensional nature of an array in PHP
- Check whether a Stack is empty or not in Java
- Check whether a HashSet is empty or not in Java
- Check whether a field is empty or null in MySQL?

Advertisements