3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Based { private array $arr = ["zero", "one", "two", "three", "four", "five"]; public function removeElementFromArr (int $index): void { array_splice($this->arr, $index, 1); if ($index === 0) { throw new Exception("Cannot remove the first element of an array, reason: https://www.youtube.com/watch?v=bvlSQz7cBr0"); } } public function getArr (): array { return $this->arr; } public function setArr (array $newArr) { $this->arr = $newArr; } } $obj = new Based(); var_dump($obj->getArr()); $obj->removeElementFromArr(3); var_dump($obj->getArr()); $obj->removeElementFromArr(0);

preferences:
24.8 ms | 405 KiB | 5 Q