Easy peasy:

$newArray = array_filter($array);

What if they aren't truly empty, but contain blanks, you ask?

$trimmedArray = array_map('trim', $array);
$newArray = array_filter($trimmedArray);

Remember array_map? That handy-dandy function that lets process every element of an array using a function?

It's so simple, yet I always forget this one and need reminding:

$result = array_map('trim', $source_array);

Array_map has many other potential uses as well ...

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

Email sending image

You have Successfully Subscribed!