I want to remove empty elements from an array. I have a $_POST-String which is set to an array by explode(). Then I'am using a loop to remove the empty elements. But that does not work. I also tried array_filter(), but with no succes. Can you help me? See Code below:
$cluster = explode("\n", $_POST[$nr]);
print_r ($cluster);
echo "<br>";
for ($i=0 ; $i<=count($cluster);$i++)
{
if ($cluster[$i] == '')
{
unset ( $cluster[$i] );
}
}
print_r ($cluster);
echo "<br>";
Result:
Array ( [0] => Titel1 [1] => Titel2 [2] => Titel3 [3] => [4] => [5] => )
Array ( [0] => Titel1 [1] => Titel2 [2] => Titel3 [3] => [4] => )