Snippet. PHP. Remove Empty Elements from Array

Recently had an array serialized into a string separated with ; which had to be brought back to array. The empty elements were of course not needed. So here is how to remove the empty elements.

$rooms = array_filter(explode(';', $rooms), create_function('$a','return $a!="";'));

Updated on: 23 Nov 2024