Skip to content

Instantly share code, notes, and snippets.

@amitayh
Created January 4, 2015 08:55
Show Gist options
  • Save amitayh/634ecba378ca072994c2 to your computer and use it in GitHub Desktop.
Save amitayh/634ecba378ca072994c2 to your computer and use it in GitHub Desktop.
<?php
class DigitsIterator implements Iterator {
private $num;
private $radix;
private $temp;
private $key;
public function __construct($num, $radix = 10) {
$this->num = $num;
$this->radix = $radix;
}
public function current() {
return $this->temp % $this->radix;
}
public function key() {
return $this->key;
}
public function next() {
$this->temp = floor($this->temp / $this->radix);
$this->key++;
}
public function rewind() {
$this->temp = $this->num;
$this->key = 0;
}
public function valid() {
return $this->temp > 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment