How to remove empty values from an array in PHP

How to remove empty values from an array in PHP

In this post we will give you information about How to remove empty values from an array in PHP. Hear we will give you detail about How to remove empty values from an array in PHPAnd how to use it also give you demo for it if it is necessary.

Use the PHP array_filter() function

You can use the PHP array_filter() function to remove or filter empty or false values from an array. This function typically filters the values of an array using a callback function, however if no callback function is specified, all the values of the array which are equal to FALSE will be removed, such as an empty string or a NULL value. Let’s take a look at an example:

<?php
$array = array("apple", "", 2, null, -5, "orange", 10, false, "");
var_dump($array);
echo "<br>";
 
// Filtering the array
$result = array_filter($array);                 
var_dump($result);
?>

 

Hope this code and post will helped you for implement How to remove empty values from an array in PHP. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US