Implementing the traversable Iterator : foreach « Statement « PHP






Implementing the traversable Iterator

 
<?php
    class IterateExample {
        public $var_one = 1;
        public $var_two = 2;
        private $var_three = 3;
        public $var_four = 4;
    }

    $inst = new IterateExample();

    foreach($inst as $key => $value) {
        echo "$key = $value\n";
    }
?>
  
  








Related examples in the same category

1.Foreach Demo
2.Looping through an Enumerated Array
3.Array element order and foreach()
4.Iterating through a multidimensional array with foreach()
5.Modifying an array with foreach()
6.Using foreach() to Iterate Through an Array
7.Using foreach() with numeric arrays
8.Displaying the contents of an array using a loop
9.Iterating Through Object Properties