1PHP By Wandering Weevil on Mar 8 2020
2$person = new StdClass();
3$person->name = "Ngbokoli";
4$person->age = 31;
5$person->nationnality = "Congolese";
6$person->profession = "Student";
7
8foreach ($person as $key => $value) {
9 echo $key." ".$value."\n";
10}
1
2<?php
3class MyClass
4{
5 public $var1 = 'valeur 1';
6 public $var2 = 'valeur 2';
7 public $var3 = 'valeur 3';
8
9 protected $protected = 'variable protégée';
10 private $private = 'variable privée';
11
12 function iterateVisible() {
13 echo "MyClass::iterateVisible:\n";
14 foreach ($this as $key => $value) {
15 print "$key => $value\n";
16 }
17 }
18}
19
20$class = new MyClass();
21
22foreach($class as $key => $value) {
23 print "$key => $value\n";
24}
25echo "\n";
26
27
28$class->iterateVisible();
29
30