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 { $tmp = $this->getArr(); array_splice($tmp, $index, 1); $this->setArr($tmp); } 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());
Output for 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25, 8.4.1 - 8.4.12
array(6) { [0]=> string(4) "zero" [1]=> string(3) "one" [2]=> string(3) "two" [3]=> string(5) "three" [4]=> string(4) "four" [5]=> string(4) "five" } array(5) { [0]=> string(4) "zero" [1]=> string(3) "one" [2]=> string(3) "two" [3]=> string(4) "four" [4]=> string(4) "five" }

preferences:
66.53 ms | 407 KiB | 5 Q