php loop through objects code example
Example 1: php loop through objects
foreach($class as $key => $value) {
print "$key => $value\n";
}
Example 2: php loop through object
foreach ($obj as $key => $value) {
echo "$key => $value\n";
}
Example 3: 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";
}
Example 4: loop through object php
<?php
class MyClass
{
public $var1 = 'valeur 1';
public $var2 = 'valeur 2';
public $var3 = 'valeur 3';
protected $protected = 'variable protégée';
private $private = 'variable privée';
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();
Example 5: php loop through objects
foreach ($obj as $key => $value) {
echo "$key => $value\n";
}
Example 6: php loop through obect
PHP By Wandering Weevil on Mar 8 2020
$person = new StdClass();
$person->name = "Ngbokoli";
$person->age = 31;
$person->nationnality = "Congolese";
$person->profession = "Student";
foreach ($person as $key => $value) {
echo $key." ".$value."\n";
}