Martin Scotta wrote:
Hi all
I have this in a simple routine...
for($i=0, $if=count($array); $i<$if; ++$i)
if( $array[$i] == '' )
{
array_splice( $array, $i, 1);
--$i;
--$if;
}
My question: is this the better way to do it?
<?php
foreach( array_keys( $array ) as $key )
{
if( (string)$array[$key] === '' )
{
unset( $array[$key] );
}
}
?>
The above will not remove a value of '0' which IMHO is not empty. If you
actually want to get rid of '0' also, then change === to == and remove
the (string) cast.
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php