Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Object Iteration?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 113
    Comment on it

    In PHP we can iterate any object by using the list of items,for getting list of items we have foreach loop in php. So that there will only the visible properties is being listed.

    We have loops concept for iterating throughout data list in php.

    Following is the simple example for object iteration :

    class TestClass{
        public $public='PublicVal';
        protected $protected='ProtectedVal';
        private $private='PrivateVal';
    
        function myfunc() {
            return 'func';
        }
    
        function iterateVisible(){
            foreach($this as $key => $value) {
               print "$key => $value\n";
           }
        }
    }
    
    $obj=new TestClass();
    $obj->iterateVisible(); 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: