Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 ...
Advertisements