P粉4474950692023-09-02 12:10:35
您需要建立一個名為Site的額外類,並傳回一個物件數組。
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; } }
然後傳回網站陣列:
return [ (new Site(1, '开罗', 'T-Rex骨骼')), (new Site(2, '吉萨', '迅猛龙骨骼')), (new Site(3, '亚历山大', '腕龙骨骼')) ];