You are here

protected function D::descender in QueryPath 6

Same name and namespace in other branches
  1. 7.3 qpa/qpa.phpunit.inc \D::descender()
  2. 7.2 qpa/qpa.phpunit.inc \D::descender()

Search a nested array.

This will recurse through n-deep arrays, storing a collection of matches.

Parameters

$name: String name of the item to search for. If searching for an atribute, prepend this with '#'.

$items: An associative array of items to seek.

$value: An (optional) value to search for. If this is specified, both name and value must be matched before an item is considered a match.

$matches: An array of matches. This is typically only used when recursing. Don't use it unless you know what you are doing.

1 call to D::descender()
D::descendList in qpa/qpa.phpunit.inc
Descend through a list and find matches.

File

qpa/qpa.phpunit.inc, line 129

Class

D

Code

protected function descender($name, $items, $value = NULL, &$matches = array(), $prefix = array()) {

  // XXX: this could be expanded to handle traversables.
  if (!is_array($items)) {
    return $matches;
  }
  foreach ($items as $n => $v) {
    if ($n == $name) {

      // If value is set, then we do a comparison
      if (isset($value)) {

        // If the comparison matches, add the item to matches.
        if ($value == $v) {
          $key = $prefix;
          $key[] = $name;
          $matches[] = $key;
        }
      }
      else {
        $key = $prefix;
        $key[] = $name;
        $matches[] = $key;
      }
    }
    if (is_array($v)) {

      // Recurse
      $base = $prefix;
      $base[] = $n;
      $this
        ->descender($name, $v, $value, $matches, $base);
    }
  }
  return $matches;
}