fruffl icon

Iterator::key() as object

fruffl | 09/21/13 09:02:54 AM UTC | 0 ⭐ | 278 👁️ | Never ⏰ | []
PHP |

560 B

|

None

|

0 👍

/

0 👎

 
    class b implements Iterator
    {
        private $p  = 0;
        private $d  = [];
        
        function add($o1, $o2)
        {
            $this->d[] = [$o1, $o2];
        }
        
        function key()
        {
            return $this->d[$this->p][0];
        }
        
        function rewind()
        {
            $this->p = 0;
        }
        
        function current()
        {
            return $this->d[$this->p][1];
        }
        
        function next()
        {
            ++$this->p;
        }
        
        
        function valid()
        {
            return isset($this->d[$this->p]);
        }
        
    }
    
    $b = new b;
    $b->add(new Str, new Str);
    
    
    foreach($b as $k => $v)
        var_dump($k); // object Str

Comments