pQuery\DomNode::getChildrenByCallback PHP Method

getChildrenByCallback() public method

Finds children using a callback function
public getChildrenByCallback ( callable $callback, boolean | integer $recursive = true, boolean $check_self = false ) : array
$callback callable Function($node) that returns a bool
$recursive boolean | integer Check recursively
$check_self boolean Include this node in search?
return array
    function getChildrenByCallback($callback, $recursive = true, $check_self = false)
    {
        $count = $this->childCount();
        if ($check_self && $callback($this)) {
            $res = array($this);
        } else {
            $res = array();
        }
        if ($count > 0) {
            if (is_int($recursive)) {
                $recursive = $recursive > 1 ? $recursive - 1 : false;
            }
            for ($i = 0; $i < $count; $i++) {
                if ($callback($this->children[$i])) {
                    $res[] = $this->children[$i];
                }
                if ($recursive) {
                    $res = array_merge($res, $this->children[$i]->getChildrenByCallback($callback, $recursive));
                }
            }
        }
        return $res;
    }
DomNode