I want to remove empty values from an array. I have tried array_filter, array_diff and a custom coded function but nothing helped.
Here's my code that generates the array:
for($i=0;$i<$_POST['size'];$i++)
{
$e = array();
if(!@strcasecmp("yes", $_POST['email'.$i]))
{
//array_push($e, $_POST['u'.$i]);
$e[$i] = $_POST['u'.$i];
}
else
{
$e[$i] = "";
}
//var_dump($e);
var_dump($e);
}
My var_dump outputs:
array (size=1)
0 => string '12' (length=2)
string '12' (length=2)
array (size=1)
1 => string '13' (length=2)
string '13' (length=2)
array (size=1)
2 => string '' (length=0)
string '' (length=0)
array (size=1)
3 => string '' (length=0)
string '' (length=0)
array (size=1)
4 => string '' (length=0)
string '' (length=0)
array (size=1)
5 => string '' (length=0)
How would I remove these empty indexes? Any suggestions are welcome.
implodeand then convert it to a string.ith value in each iteration, but it is being wiped at every iteration too. Looks like that initialisation should go before the loop?elseclause is the problem - that seems to be what is adding the last four empty-string entries. Remove it and see if that helps?