Answers for "php loop object keys"

PHP
0

loop over keys and values php

foreach ($arr as $key => $value) {
 echo $key;
}
Posted by: Guest on May-06-2021
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 => $value\n";
       }
    }
}

$class = new MyClass();

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


$class->iterateVisible();

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

php loopthrough object

foreach ($objects as $obj) {
   echo $obj->property;
}
Posted by: Guest on May-15-2020
0

php loop object keys

echo $obj->name;
echo $obj->age;
Posted by: Guest on July-12-2020

Browse Popular Code Answers by Language