array_values() doesn't remove empty elements?
| From: | Morten Winther | Date: | Wed, 19 Jun 2002 16:08:56 +0000 |
| Subject: | array_values() doesn't remove empty elements? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-102960@lists.php.net to get a copy of this message | ||
Hello
Can you tell me why the array_values() function doesn't remove the empty
elements?
Any other solutions?
/ morten
<?php
// fra bruger
$input = 't567-t678--t679-';
// ingen t'er tak
$output = str_replace("t", "", $input);
// hit med et array
$output = explode("-", $output);
//lad os se
print_r($output);
// ingen tomme tak
$output = array_values(array_unique($output));
//lad os se igen
print_r($output);
/**
* result:
*
* Array
* (
* [0] => 567
* [1] => 678
* [2] =>
* [3] => 679
* [4] =>
* )
* Array
* (
* [0] => 567
* [1] => 678
* [2] =>
* [3] => 679
* )
*/
?>