Tuesday, September 7, 2010

HELP

class NumberSquared implements Iterator {
    public function __construct ($start, $end)
    {
        $this->start = $start;
        $this->end = $end;
    }
   
    public function rewind ()
    {
        $this->curr = $this->start;
    }
   
    public function key()
    {
        return $this->curr;
    }
   
    public function current()
    {
        return pow($this->curr,2);
    }
   
    public function next()
    {
        $this->curr++;
    }
   
    public function valid()
    {
        return $this->curr <= $this->end;
    }
   
    private $start, $end, $curr;
}

$obj = new NumberSquared(3,7);

foreach ($obj as $key => $value) {
    print "The square of $key is $value
";
}
?>