3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Odometer { public function __construct(array $values, $places){ $this->values = array_values($values); $this->places = $places; // 0=>a, 1=>b, ... prints [a],[b],... $this->output = reset($values); // [0]=>0, [0]=>1, [0]=>2, ...[] $this->register[0] = key($values); end($values); $this->limit = key($values); } public function iterate(){ for($i = 0; $i < count($register); $i++){ if($this->register[$i] > $this->limit){ $this->register[$i] = 0; if(isset($this->register[$i+1])){ $this->register[$i+1]++; } else { $this->register[$i+1] = 0; } } } $this->register[0]++; } public function setMeter(){ for($i = 0; $i < count($this->register); $i++){ $this->meter[$i] = $this->values[$this->register[$i]]; } } public function readMeter(){ $this->setMeter(); return '[' . implode('][', $this->meter) . ']'; } }

preferences:
26.11 ms | 402 KiB | 5 Q