I want to avoid any empty string in an array or any kind of white space. I'm using the following code:
<?php
$str="category 1
category 2
category 3
category 4
";
$var = nl2br($str);
echo $var."<br>";
$arr = explode("\n", $var);
var_dump($arr); echo "<br>";
for($i = 0; $i < count($arr); $i++) {
if(($arr[$i]) != '')
{
echo $arr[$i]."</br>";
}
}
?>
How can I remove the white space or empty string like the 2,3,5 index in the array which don't have needed string.