<?php
// Define a class
class Person {
public $name;
public $age;
public $gender;
public function __construct($name, $age, $gender) {
$this->name = $name;
$this->age = $age;
$this->gender = $gender;
}
}
// Create an object of the class
$person = new Person('John', 30, 'Male');
// Loop through the values of the object
foreach ($person as $key => $value) {
echo "$key: $value<br>";
}
?>
name: John
age: 30
gender: Male
foreach
` loop and printed out the key-value pairs of the object using the `$key
` and `$valu
e` variables.