Rumah > Soal Jawab > teks badan
P粉4474950692023-09-02 12:10:35
Anda perlu mencipta kelas tambahan yang dipanggil Tapak dan mengembalikan pelbagai objek.
class Site { private int $siteId; private string $name; private string $bone; /** * @param int $siteId * @param string $name * @param string $bone */ public function __construct(int $siteId, string $name, string $bone) { $this->siteId = $siteId; $this->name = $name; $this->bone = $bone; } /** * @return int */ public function getSiteId(): int { return $this->siteId; } /** * @param int $siteId */ public function setSiteId(int $siteId): void { $this->siteId = $siteId; } /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name */ public function setName(string $name): void { $this->name = $name; } /** * @return string */ public function getBone(): string { return $this->bone; } /** * @param string $bone */ public function setBone(string $bone): void { $this->bone = $bone; } }
Kemudian kembalikan tatasusunan tapak:
return [ (new Site(1, '开罗', 'T-Rex骨骼')), (new Site(2, '吉萨', '迅猛龙骨骼')), (new Site(3, '亚历山大', '腕龙骨骼')) ];