fork download
  1. <?php
  2.  
  3. class Category {
  4. public function getCategories($type){
  5. $array = [
  6. 'xxx' => 'foo',
  7. 'yyy' => 'bar'
  8. ];
  9.  
  10. return ($array[$type] ?? 'fooBar');
  11. }
  12. }
  13.  
  14. echo (new class() extends Category {})->getCategories('xxx') . PHP_EOL;
  15. echo (new class() extends Category {})->getCategories('yyy') . PHP_EOL;
  16. echo (new class() extends Category {})->getCategories('zzz') . PHP_EOL;
Success #stdin #stdout 0.02s 25896KB
stdin
Standard input is empty
stdout
foo
bar
fooBar