<?php
class City{
private $name;
private $people = [];
public function setName($vaule){
$this->name = $vaule;
}
public function getName(){
return $this->name;
}
public function addPerson($person){
$this->people[] = $person;
}
public function getPeople(){
$result = '';
foreach ($this->people as $person){
$result =$person->getName();
return $result;
}
}
}
class Person{
private $name;
public function setName($vaule){
$this->name = $vaule;
}
public function getName(){
return $this->name;
}
}
$person = new Person();
$person->setName('Misha');
$person2 = new Person();
$person2->setName('Misha2');
$person3 = new Person();
$person3->setName('Misha3');
$Moscow = new City();
$Moscow->setName('Moscow');
echo $Moscow->getName() . '<br>';
$Moscow->addPerson($person,$person2,$person3);
$Moscow->getPeople();
?>
class City
{
private $name;
private $people = [];
public function setName($vaule)
{
$this->name = $vaule;
}
public function getName()
{
return $this->name;
}
public function addPerson($person)
{
$this->people = $person;
}
public function getPeople()
{
$result = [];
foreach ($this->people as $person) {
$result[] = $person->getName();
}
return $result;
}
}
class Person
{
private $name;
public function setName($vaule)
{
$this->name = $vaule;
}
public function getName()
{
return $this->name;
}
}
$person = new Person();
$person->setName('Misha');
$person2 = new Person();
$person2->setName('Misha2');
$person3 = new Person();
$person3->setName('Misha3');
$Moscow = new City();
$Moscow->setName('Moscow');
echo $Moscow->getName() . '<br>';
$Moscow->addPerson([$person, $person2, $person3]);
print_r($Moscow->getPeople());