class Array {
private $array = [];
private $max = 10;
public function __construct(int $max = 10, $array = [])
{
$this->array = $array;
$this->max = $max;
}
public function setMax(int $max)
{
$this->setMax = $max;
return $this;
}
public function add($value)
{
if (count($this->array) < $this->max) {
$this->array[] = $value;
}
return $this;
}
public function get()
{
return $this->array;
}
}
$array = new Array(5);
$array->add(1)->add(2)->add(3)->add(4)->add(5)->add(6);
var_dump($array->get());Bu şekilde kullanabilirsin. Minimum düzeyde yazdım tabi geliştirebilirsin. add methoduna key ekleyebilirsin. Yada limiti aştığında exception verebilirsin, toArray, toJson, get($key), getAll vs vs ihtiyacına göre artık. add methoduna unshift pop vs de ekleyebilirsin.