PHP Object Iteration:
In PHP 5 a new way for objects is introduced to iterate through a list of items. In this technique we generally use foreach statement. All visible (public, protected) properties are used in the iteration. To display the private properties we can use any method which would display these all.
PHP Object Iteration Example:
<?php
class One{ public $a="A"; public $b="B"; public $c="C"; protected $pro="Protected Data"; private $pri="Private Data"; function iteration(){ echo "One::iteration<br/>"; foreach($this as $key=>$value){ print "$key=>$value<br/>";}}}
$one=new One(); echo "<b>If we call the iteration method:</b><br/>"; $one->iteration(); echo "<b>If we iterate the object:</b><br/>"; foreach($one as $key=>$value){ print "$key=>$value<br/>";}
?>
Output:
If we call the iteration method:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.