} public function Reset() { $this->values = $this->start_ranges; $this->index = 0; } public function ResetEnd() { $this->values = $this->end_ranges; $this->index = $this->final_index; } } $pretty = function ($v = '', $c = " ", $in = -1, $k = null) use(&$pretty) { $r = ''; if (in_array(gettype($v), array('object', 'array'))) { $r .= ($in != -1 ? str_repeat($c, $in) : '') . (is_null($k) ? '' : "{$k}: ") . '<br>'; foreach ($v as $sk => $vl) { $r .= $pretty($vl, $c, $in + 1, $sk) . '<br>'; } } else { $r .= ($in != -1 ? str_repeat($c, $in) : '') . (is_null($k) ? '' : "{$k}: ") . (is_null($v) ? '<NULL>' : "<strong>{$v}</strong>"); } return $r; }; $c = new Counter(array(array(1, 5, 1), array(0, 3, 10))); $c->ResetEnd(); do { echo $pretty($c->index); echo '<br>'; $c->CountDown(); } while (!$c->finished);