PHP : é£æ³é åã®valueã«ãªãã¸ã§ã¯ããæ ¼ç´ãããã¿ã¼ã³
<?php class Person { public $name; public $age; public function __construct($name, $age){ $this->name = $name; $this->age = $age; } public function introduce(){ echo "Hi my name is " . $this->name . "\n"; } } $people = [ "person1" => new Person("Bob", 22), "person2" => new Person("mary", 30) ]; // Hi my name is Bob // Hi my name is mary foreach ($people as $person) { $person->introduce(); }