ItSolutionStuff.com

How to Check Array Empty or Not in PHP?

By Hardik Savani • May 14, 2024
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

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Merge Two Arrays with Unique Values in PHP?

Read Now →

How to Merge Two Array in PHP?

Read Now →

How to Remove Numeric Keys in PHP Array?

Read Now →

How to Remove String Values in PHP Array?

Read Now →

How to Remove Numeric Values in PHP Array?

Read Now →

How to Get First 2 Elements of Array in PHP?

Read Now →

How to Get Last 5 Elements of Array in PHP?

Read Now →

How to Get Random Value from an Array in PHP?

Read Now →

How to Get First Element of Array in PHP?

Read Now →

How to Add Prefix in Each Key of PHP Array?

Read Now →

How to Get Minimum Key Value of Array in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →