Reputation: 981
I get from a from a list:
one "\n"
"\n"
two "\n"
I do an explode when I get the list:
$list_explode_nl = explode("\n", $list);
var_dump shows:
array(3) { [0]=> string(5) "one " [1]=> string(1) " " [2]=> string(4) "two" }
My code:
foreach ($list_explode_nl as $k => $v) {
if ($v == NULL || $v == ' ') {
unset($list_explode_nl[$k]);
}
}
I want to get rid of an element, when the string is like [1]. How?
Upvotes: 0
Views: 52
Reputation: 212452
$list_explode_nl = array_filter(array_map('trim',$list_explode_nl));
or
$list_explode_nl = array_values(array_filter(array_map('trim',$list_explode_nl)));
if you want to reset the indexes as well
Upvotes: 1