php loop object

104

php loop object -

<?php
class MyClass
{
    public $var1 = 'value 1';
    public $var2 = 'value 2';
    public $var3 = 'value 3';

    protected $protected = 'protected var';
    private   $private   = 'private var';

    function iterateVisible() {
       echo "MyClass::iterateVisible:\n";
       foreach ($this as $key => $value) {
           print "$key => $value\n";
       }
    }
}

$class = new MyClass();

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


$class->iterateVisible();

?>

php loop through object -

foreach ($obj as $key => $value) {
    echo "$key => $value\n";
    //echo "test greper";
}

php loop through objects -

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

php loop through object -

foreach ($objects as $obj){
      echo $obj->user->description;
}

Comments

Submit
0 Comments