You are here

function D::setVal in QueryPath 6

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

Set the value of an item in a deeply nested array.

File

qpa/qpa.phpunit.inc, line 67

Class

D

Code

function setVal($key, $value) {
  $t =& $this->arr;
  $c = count($key);
  for ($i = 0; $i < $c; ++$i) {
    $part = $key[$i];
    if ($c - 1 == $i) {
      $t[$part] = $value;
    }
    else {
      $t =& $t[$part];
    }
  }
  return $t;
}