How to Remove All Empty Elements in the PHP Array?

03-Apr-2023

.

Admin

How to Remove All Empty Elements in the PHP Array?

Hi Dev,

This tutorial is focused on how to remove all empty elements in a PHP array. you'll learn how to remove all empty elements in the array. We will use how to remove empty elements in a PHP array. if you have a question about how to remove empty elements in the array then I will give a simple example with a solution.

Now, let's see the article on how to remove empty elements in the PHP array. it's a simple example of how to remove empty elements in the array. you can understand the concept of how to remove empty elements in a PHP array. if you have a question about how to remove empty elements in the array then I will give a simple example with a solution.

Example:


index.php

<?php

$myArray = ["", 1, 2, 3, 4, 5];

// Get remove empty elements of array list

$newArray = array_filter($myArray);

print_r($newArray);

?>

Output:

Array (

[1] => 1

[2] => 2

[3] => 3

[4] => 4

[5] => 5

)

I hope it could help you...

#PHP