How to remove empty elements from an array in PHP
PHP has a built-in array_filter()
function by using that we can remove the empty elements from an array.
Here is an example, that removes the empty strings from a given array.
$fruits = array("apple", "", "avocado", "grapes", 20, "","");
print_r(array_filter($fruits));
Output:
Array
(
[0] => apple
[2] => avocado
[3] => grapes
[4] => 20
)