<?php

class Record {
    private $data = [];
    private $currentIndex = 0;

    public function addRecord($value) {
        $this->data[] = $value;
    }

    public function getRecord() {
        if ($this->currentIndex < count($this->data)) {
            $record = $this->data[$this->currentIndex];
            $this->currentIndex++;
            return $record;
        } else {
            return null;
        }
    }
}

// Vytvoření instance třídy
$recordKeeper = new Record();

// Přidání záznamů
$recordKeeper->addRecord("John");
$recordKeeper->addRecord(30);
$recordKeeper->addRecord("New York");

// Získání a postupné procházení všech záznamů pomocí cyklu foreach a metody getRecord()
echo "All records:<br>";
while ($record = $recordKeeper->getRecord()) {
    echo $record . "<br>";
}