QueryPath\DOMQuery::each PHP Method

each() public method

Rules of the callback: - A callback is passed two variables: $index and $item. (There is no special treatment of $this, as there is in jQuery.) - You will want to pass $item by reference if it is not an object (DOMNodes are all objects). - A callback that returns FALSE will stop execution of the each() loop. This works like break in a standard loop. - A TRUE return value from the callback is analogous to a continue statement. - All other return values are ignored.
See also: eachLambda()
See also: filter()
See also: map()
public each ( callback $callback )
$callback callback The callback to run.
    public function each($callback)
    {
        if (is_callable($callback)) {
            $i = 0;
            foreach ($this->matches as $item) {
                if (call_user_func($callback, $i, $item) === false) {
                    return $this;
                }
                ++$i;
            }
        } else {
            throw new \QueryPath\Exception('Callback is not callable.');
        }
        return $this;
    }