Answers for "php objects loop through"

4

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 => $valuen";
       }
    }
}

$class = new MyClass();

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


$class->iterateVisible();

?>
Posted by: Guest on February-21-2020
2

php loop through object

$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}$person = new StdClass();
$person->name = "Taylor";
$person->age = 31;

foreach ($person as $key => $value) {
    echo $key.",".$value."n";
}
Posted by: Guest on June-11-2020

Code answers related to "php objects loop through"

Browse Popular Code Answers by Language