Removes an element from an array as defined by `$path`.

@param mixed $list From where to remove.
@param mixed $path A dot-delimited string.
@return array Array with `$path` removed from its value.
435827
public static function remove($list, $path = null) {
		if (empty($path)) {
			return $list;
		}
		if (!is_array($path)) {
			$path = explode('.', $path);
		}
		$_list =& $list;

		foreach ($path as $i => $key) {
			if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
				$key = (integer) $key;
			}
			if ($i === count($path) - 1) {
				unset($_list[$key]);
			} else {
				if (!isset($_list[$key])) {
					return $list;
				}
				$_list =& $_list[$key];
			}
		}
		return $list;
	}
1026234
public function arrayUnset(array $data, string $path)
    {
        $dot = new Dot($data);
        $dot->delete($path);

        return $dot->all();
    }
999994
public static function removeByPath(array &$data, $path, $separator = '.')
    {
        $nodes = static::getPathNodes($path, $separator);

        if (empty($nodes)) {
            return false;
        }

        $previous = null;
        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (is_array($dataTmp)) {
                if (empty($dataTmp[$node])) {
                    return false;
                }

                $previous = &$dataTmp;
                $dataTmp = &$dataTmp[$node];
            } else {
                return false;
            }
        }

        // Now, path go to the end, means we get latest node, set value to this node.
        unset($previous[$node]);

        return true;
    }
950097
public function delete($path)
    {
        $node = $this->getNodeForPath($path);
        $node->delete();

        list($parent) = Uri\split($path);
        $this->markDirty($parent);
    }
1244975
public function recursive($path, &$list = array(), $limit = 4)
    {
        if(!$path) return;
        if($limit == 0) return;
        $files = scandir($path);
        foreach ($files as $file) {
            if ($file !== '.' && $file !== '..' && !$this->isCommonDirectory($file)) {
                $filename = $path . '/' . $file;
                if (is_dir($filename)) {
                    $this->recursive($filename, $list, $limit - 1);
                } else {
                    if ($file === 'config.yml' && !in_array($filename, $list)) {
                        $list[] = $filename;
                    }
                }
            }
        }
    }
295494
public static function readAndDelete($path)
    {
        $path = self::normalizePath($path);
        $contents = file_get_contents($path);
        if ($contents === false) {
            return false;
        }
        self::removeFile($path);
        return $contents;
    }
1027738
private function removeDirectory(string $path): bool
    {
        $iterator = new DirectoryIterator($path);
        foreach ($iterator as $fileInfo) {
            if ($fileInfo->isDot() || !$fileInfo->isDir()) {
                continue;
            }
            $dirName = $fileInfo->getPathname();
            $this->removeDirectory($dirName);
        }

        $files = new FilesystemIterator($path);

        /** @var SplFileInfo $file */
        foreach ($files as $file) {
            $fileName = $file->getPathname();
            unlink($fileName);
        }

        return rmdir($path);
    }
780006
public static function untrailingslash(&$path) {
		if (\is_array($path)) {
			foreach ($path as $k=>$v) {
				static::untrailingslash($path[$k]);
			}
		}
		else {
			cast::string($path, true);

			static::unixslash($path);
			$path = \rtrim($path, '/');
		}
	}
1240219
public static function delete(array &$values, $path)
    {
        /** @noinspection ReferenceMismatchInspection */
        if (!static::isArray($values)) {
            // This is not an array!
            return false;
        }

        if (is_array($path)) {
            // The path has already been separated into segments
            $segments = $path;
        } else {
            $path = (string) $path;

            // Remove starting delimiters and spaces
            $path = ltrim($path, sprintf('%s ', static::PATH_DELIMITER));
            // Remove ending delimiters, spaces, and wildcards
            $path = rtrim($path, sprintf('%s %s', static::PATH_DELIMITER, static::PATH_WILDCARD));
            // Split the segments by delimiter
            $segments = explode(static::PATH_DELIMITER, $path);
        }

        while (count($segments) > 1) {
            $key = array_shift($segments);

            /** @noinspection ReferenceMismatchInspection */
            if (!array_key_exists($key, $values) || !is_array($values[$key])) {
                return false;
            }

            $values =& $values[$key];
        }

        unset($values[array_shift($segments)]);

        return true;
    }
294500
public static function removeByPath(&$data, $path, $separator = '.')
    {
        $nodes = array_values(array_filter(explode($separator, $path), 'strlen'));

        if (empty($nodes)) {
            return false;
        }

        $previous = null;
        $dataTmp = &$data;

        foreach ($nodes as $node) {
            if (is_object($dataTmp)) {
                if (empty($dataTmp->$node)) {
                    return false;
                }

                $previous = &$dataTmp;
                $dataTmp = &$dataTmp->$node;
            } elseif (is_array($dataTmp)) {
                if (empty($dataTmp[$node])) {
                    return false;
                }

                $previous = &$dataTmp;
                $dataTmp = &$dataTmp[$node];
            } else {
                return false;
            }
        }

        // Now, path go to the end, means we get latest node, set value to this node.
        if (is_object($previous)) {
            unset($previous->$node);
        } elseif (is_array($previous)) {
            unset($previous[$node]);
        }

        return true;
    }
1282039
public static function insert($list, $path, $data = []) {
		if (!is_array($path)) {
			$path = explode('.', $path);
		}
		$_list =& $list;

		foreach ($path as $i => $key) {
			if (is_numeric($key) && (integer) $key > 0 || $key === '0') {
				$key = (integer) $key;
			}
			if ($i === count($path) - 1) {
				$_list[$key] = $data;
			} else {
				if (!isset($_list[$key])) {
					$_list[$key] = [];
				}
				$_list =& $_list[$key];
			}
		}
		return $list;
	}
927400
private function removePath(string $path): void
    {
        if (false !== strpos($path, '*')) {
            $paths = glob($path);
            foreach ($paths as $path) {
                $this->removePath($path);
            }
        } else {
            if (is_dir($path)) {
                $iterator = new \RecursiveDirectoryIterator($path);
                $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::CHILD_FIRST);
                /** @var \SplFileInfo $file */
                foreach ($iterator as $file) {
                    if ('.' === $file->getBasename() || '..' === $file->getBasename()) {
                        continue;
                    }
                    if ($file->isLink() || $file->isFile()) {
                        unlink($file->getPathname());
                    } else {
                        rmdir($file->getPathname());
                    }
                }
                rmdir($path);
            } else {
                if (is_file($path)) {
                    unlink($path);
                }
            }
        }
    }
711059
public function deleteRecursive($path)
	{
		if (!$this->tryDelete($path)) {
			foreach ((array) $this->nlist($path) as $file) {
				if ($file !== '.' && $file !== '..') {
					$this->deleteRecursive(strpos($file, '/') === FALSE ? "$path/$file" : $file);
				}
			}
			$this->rmdir($path);
		}
	}
430331
protected function clearDir($path)
    {
        $items = [];
        $finder = new Finder();
        $finder->in($path)
            ->ignoreVCS(false)
            ->ignoreDotFiles(false);

        foreach ($finder as $item) {
            $items[] = $item->getRealpath();
        }

        if (count($items) > 0) {
            $this->fs->remove($items);
        }
    }
139419
static public function remove($path)
    {
        $returnValue = (bool) false;

        if (is_file($path)) {
            $returnValue = unlink($path);
        } elseif (is_dir($path)) {
            /*
             * //It seems to raise problemes on windows, depending on the php version the resource handler is not freed with DirectoryIterator preventing from further deletions // $iterator = new DirectoryIterator($path); foreach ($iterator as $fileinfo) { if (!$fileinfo->isDot()) { } }
             */
            $handle = opendir($path);
            if ($handle !== false) {
                while (false !== ($entry = readdir($handle))) {
                    if ($entry != "." && $entry != "..") {
                        self::remove($path . DIRECTORY_SEPARATOR . $entry);
                    }
                }
                closedir($handle);
            } else {
                throw new common_exception_Error('"' . $path . '" cannot be opened for removal');
            }

            $returnValue = rmdir($path);
        } else {
            throw new common_exception_Error('"' . $path . '" cannot be removed since it\'s neither a file nor directory');
        }

        return (bool) $returnValue;
    }
1120892
public function remove($path)
    {
        $path = explode($this->separator, $path);
        $last = array_pop($path);

        $item = &$this->item;

        foreach ($path as $key) {
            if (array_key_exists($key, $item) && is_array($item[$key])) {
                $item = &$item[$key];
                continue;
            }
            return false;
        }
        
        if (array_key_exists($last, $item)) {
            unset($item[$last]);
            return true;
        }

        return false;
    }
1028455
public function remove($path)
	{
		// Cheap optimisation to direct remove the node if there is no separator
		if (!strpos($path, $this->separator))
		{
			$result = (isset($this->data->$path) && $this->data->$path !== null && $this->data->$path !== '') ? $this->data->$path : null;

			unset($this->data->$path);

			return $result;
		}

		/*
		 * Explode the registry path into an array and remove empty
		 * nodes that occur as a result of a double separator. ex: joomla..test
		 * Finally, re-key the array so they are sequential.
		 */
		$nodes = array_values(array_filter(explode($this->separator, $path), 'strlen'));

		if (!$nodes)
		{
			return;
		}

		// Initialize the current node to be the registry root.
		$node   = $this->data;
		$parent = null;

		// Traverse the registry to find the correct node for the result.
		for ($i = 0, $n = \count($nodes) - 1; $i < $n; $i++)
		{
			if (\is_object($node))
			{
				if (!isset($node->{$nodes[$i]}) && ($i !== $n))
				{
					continue;
				}

				$parent = &$node;
				$node   = $node->{$nodes[$i]};

				continue;
			}

			if (\is_array($node))
			{
				if (($i !== $n) && !isset($node[$nodes[$i]]))
				{
					continue;
				}

				$parent = &$node;
				$node   = $node[$nodes[$i]];

				continue;
			}
		}

		// Get the old value if exists so we can return it
		switch (true)
		{
			case \is_object($node):
				$result = isset($node->{$nodes[$i]}) ? $node->{$nodes[$i]} : null;
				unset($parent->{$nodes[$i]});

				break;

			case \is_array($node):
				$result = isset($node[$nodes[$i]]) ? $node[$nodes[$i]] : null;
				unset($parent[$nodes[$i]]);

				break;

			default:
				$result = null;

				break;
		}

		return $result;
	}