php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #25188 array_compact
Submitted: 2003-08-21 08:45 UTC Modified: 2004-01-10 10:07 UTC
From: jari at reputation dot fi Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.3RC4 OS: All
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jari at reputation dot fi
New email:
PHP Version: OS:

 

 [2003-08-21 08:45 UTC] 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
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-08-21 10:50 UTC] jay@php.net
Wouldn't array_filter() provide what you're looking for? 
 
J 
 [2004-01-10 10:07 UTC] andrey@php.net
array_filter() with callback NULL will do the job.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 15:01:28 2024 UTC