How to get rid off empty elements of an array?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi to all!

I have a form with 6 text fields where visitor has to enter product serial
number (same type data). he has to enter AT LEAST ONE.

for ($i=0; $i<6; $i++)
{
    echo '<input type="text" name="PSN['.$i.']" value="'.$PSN[$i].'"
size="25">';
}

After the form is submitted I'm getting an array

Array
(
    [0] => abc123
    [1] => ddd111
    [2] => poi987
    [3] =>
    [4] =>
    [5] =>
)

Now, I need to get rid off empty elements of the array, to get this:

Array
(
    [0] => abc123
    [1] => ddd111
    [2] => poi987
)

To do that I tried:
foreach ($PSN as $value)
{
   if (!empty($value))    $PSN_New[] = $value;
}
but every time I'm getting one additional element of the array:

I tried
foreach ($PSN as $value)
{
   if ($value != '')    $PSN_New[] = $value;
}
too - same result.

Array
(
    [0] => abc123
    [1] => ddd111
    [2] => poi987
    [3] =>
)

No space or anything else is "entered" in 4th field.

What I'm doing wrong?

Thanks for any help.

-afan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux