- array_push: documentation ( source)
- implode: documentation ( source)
- explode: documentation ( source)
- array_pop: documentation ( source)
<?php
class Path {
public $currentPath;
private $array;
function __construct($path) {
$this->currentPath = $path;
$array = explode("/", $path);
}
public function cd($newPath) {
$change = explode("/", $newPath);
foreach ($change as $value) {
if ($value == "..") {
if (count($array) > 0) {
array_pop($array);
}
} else {
array_push($array, $value);
}
}
$currentPath = implode("/", $array);
}
}
$path = new Path('/a/b/c/d');
echo $path->cd('../x')->currentPath;