#25188 [Opn]: array_compact

From: Date: Thu, 21 Aug 2003 15:50:43 +0000
Subject: #25188 [Opn]: array_compact
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-46428@lists.php.net to get a copy of this message
 ID:               25188
 Updated by:       jay@php.net
 Reported By:      jari at reputation dot fi
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: All
 PHP Version:      4.3.3RC4
 New Comment:

Wouldn't array_filter() provide what you're looking for? 
 
J 


Previous Comments:
------------------------------------------------------------------------

[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



Thread (4 messages)

« previous php.bugs (#46428) next »