Created
January 4, 2015 08:55
-
-
Save amitayh/634ecba378ca072994c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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