コード例 #1
0
 /**
  * Remove a node
  * @return bool Returns true if node node has been removed, false if it doesn't exist already
  */
 public static function remove(&$array, $path, $handleMounting = false, $onMountHit = null)
 {
     $path = new Path($path);
     if ($path->root()) {
         throw new MyceliumException("Cannot remove entire array.");
     }
     $node =& $array;
     for ($i = 0; $i < $path->length(); $i++) {
         // is the current node a mounted node?
         if ($handleMounting && array_key_exists("@mount", $node)) {
             // callback(mounterClass, relativePath, pathToTheMountNode)
             $onMountHit($node["@mount"], $path->cut($i), $path->clamp($i));
         }
         // does the next node exist?
         if (!array_key_exists($path[$i], $node)) {
             return false;
         }
         // last path segment?
         if ($i == $path->length() - 1) {
             // remove the node
             unset($node[$path[$i]]);
             return true;
         }
         // is the next node an array?
         if (!is_array($node[$path[$i]])) {
             return false;
         }
         // continue deeper
         $node =& $node[$path[$i]];
     }
 }