InterviewSolution
| 1. |
What Is Object Iteration? |
|
Answer» PHP provides a way for objects to be iterate through a list of items, for this we can use foreach. Only visible properties will be LISTED. CLASS TestClass{ PUBLIC $public='PublicVal'; protected $protected='ProtectedVal'; private $private='PrivateVal'; function myfunc() { RETURN 'func'; } function iterateVisible(){ foreach($this as $key => $value) { print "$key => $valuen"; } } } $obj=new TestClass(); $obj->iterateVisible(); PHP provides a way for objects to be iterate through a list of items, for this we can use foreach. Only visible properties will be listed. class TestClass{ public $public='PublicVal'; protected $protected='ProtectedVal'; private $private='PrivateVal'; function myfunc() { return 'func'; } function iterateVisible(){ foreach($this as $key => $value) { print "$key => $valuen"; } } } $obj=new TestClass(); $obj->iterateVisible(); |
|