filter ( $callback, $bind )

Filters the list of nodes by passing each value in the current CFArray object through a function. The node will be removed if the function returns false.

The callback function takes three parameters:

  • $item - mixed - Optional - The individual node in the array.
  • $key - mixed - Optional - The key for the array node.
  • $bind - mixed - Optional - The variable that was passed into the $bind parameter.

Access

public

Parameters

Parameter

Type

Required

Description

$callback

string
function

Required

The callback function to execute. PHP 5.3 or newer can use an anonymous function.

$bind

mixed

Optional

A variable from the calling scope to pass-by-reference into the local scope of the callback function.

Returns

Type

Description

CFArray

A new CFArray object containing the return values.

Source

Method defined in utilities/array.class.php | Toggle source view (15 lines) | View on GitHub

public function filter($callback, &$bind = null)
{
    $items = $this->getArrayCopy();
    $collect = array();

    foreach ($items as $key => &$item)
    {
        if ($callback($item, $key, $bind) !== false)
        {
            $collect[] = $item;
        }
    }

    return new CFArray($collect);
}

Copyright © 2010–2013 Amazon Web Services, LLC


Feedback