note 43614 deleted from function.array-splice by felipe

From: Date: Sat, 05 Jan 2008 02:08:48 +0000
Subject: note 43614 deleted from function.array-splice by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134819@lists.php.net to get a copy of this message
Note Submitter: reverse esacdaehasinhoj at oohay dot moc ---- Also, a quick function to discard empty entries in an array which otherwise keeps keys intact: <?php function remove_empty($inarray) { if (is_array($inarray)) { foreach($inarray as $k=>$v) { if (!(empty($v))) { $out[$k]=$v; } } return $out; } else { return $inarray; } } // easy enough? print_r(remove_empty(array('', 'foo', '', 'bar', '', '', 'baz', ''))); ?> Should return: Array ( [1] => foo [3] => bar [6] => baz )

« previous php.notes (#134819) next »