|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-08-21 10:50 UTC] jay@php.net
[2004-01-10 10:07 UTC] andrey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 18:00:01 2025 UTC |
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 )