ItSolutionStuff.com

How to Remove Empty Values from Array in PHP?

By Hardik Savani • May 14, 2024
PHP

you have array with empty value and you want to remove all empty value from that array without loop. you can remove your all empty value from array without loop. PHP array_filter function through you can remove all empty value, you can do both way try and see following example how to do this :

Example:

<?php

$example = array(100, "hari", "","hey", "", 77, "hello");

$result = array_filter($example, function($value) {

return !empty($value);

});

print_r($result);

?>

Output:

Array

(

[0] => 100

[1] => hari

[3] => hey

[5] => 77

[6] => hello

)

I hope it can help you...

Tags: PHP
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 Convert String into Array in PHP?

Read Now →

How to Install Apache PHP MySQL and Phpmyadmin on Ubuntu?

Read Now →

Laravel Like Dislike System Tutorial Example

Read Now →

PHP Ajax Multiple Image Upload with Preview Example

Read Now →

How to Remove Duplicate Values from Array in PHP?

Read Now →

How to Remove White Space from String in PHP?

Read Now →

How to Get First Element of Array in Javascript?

Read Now →

How to Remove undefined Value from Array in JQuery?

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 access PHP variables in JQuery?

Read Now →

How to Find Day Name from Specific Date in PHP?

Read Now →

How to Remove Null Values from Array in PHP?

Read Now →