#25188 [Opn->Csd]: array_compact
| From: | andrey@php.net | Date: | Sat, 10 Jan 2004 15:07:16 +0000 |
| Subject: | #25188 [Opn->Csd]: array_compact | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-53055@lists.php.net to get a copy of this message | ||
ID: 25188
Updated by: andrey@php.net
Reported By: jari at reputation dot fi
-Status: Open
+Status: Closed
Bug Type: Feature/Change Request
Operating System: All
PHP Version: 4.3.3RC4
New Comment:
array_filter() with callback NULL will do the job.
Previous Comments:
------------------------------------------------------------------------
[2003-08-21 10:50:43] jay@php.net
Wouldn't array_filter() provide what you're looking for?
J
------------------------------------------------------------------------
[2003-08-21 08:45:52] jari at reputation dot fi
Description:
------------
Removes all array elements with empty values from a given array.
Didn't manage to find command similar to this.
Reproduce code:
---------------
function array_compact($thisArray) {
for($i = 0; $i < sizeof($thisArray); $i++) {
if($thisArray[$i] != "") {
$newArray[] = $thisArray[$i];
}
}
return $newArray;
}
Expected result:
----------------
Array
(
[0] => banana
[1] =>
[2] => apple
)
->
Array
(
[0] => banana
[1] => apple
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=25188&edit=1