class A{ public function sett($name, $var){ $this->arr[$name] = $var; } public function gett($name){ return $this->arr[$name]; } } $animal = new A; $animal->sett('Cat', ['type'=> [1,2,3,4]]); $animal->sett('Cat', ['type2'=> [1,2,3,4]]); $animal->sett('Cat', ['type3'=> [1,2,3,4]]); //spodób 1 $animal->gett('Cat')['type']; $animal->gett('Cat')['type2']; $animal->gett('Cat')['type3']; //czy sposób2 $cat = $animal->gett('Cat'); $cat['type']; $cat['type2']; $cat['type3'];
Zastanawiam się czy obydwa sposoby są równie wydajne i nie zawracać sobie nimi głowy, czy jednak używać sposób 2 jak kiedyś się używało.