fork download
  1. <?php
  2. class Kamus {
  3. private $kamus = [];
  4.  
  5. public function tambah(string $kata, array $sinonim): void {
  6. // tidak mengembalikan hasil (void)
  7.  
  8. if(!isset($this->kamus[$kata])) {
  9. $this->kamus[$kata] = [];
  10. }
  11.  
  12. foreach($sinonim as $other_kata) {
  13. if(!in_array($other_kata, $this->kamus[$kata])) {
  14. $this->kamus[$kata][] = $other_kata;
  15. }
  16.  
  17. if (!isset($this->kamus[$other_kata])) {
  18. $this->kamus[$other_kata] = [];
  19. }
  20.  
  21. if (!in_array($kata, $this->kamus[$other_kata])) {
  22. $this->kamus[$other_kata][] = $kata;
  23. }
  24. }
  25.  
  26. return;
  27. }
  28.  
  29. public function ambilSinonim(string $kata) {
  30. return $this->kamus[$kata];
  31. }
  32. }
  33.  
  34. ?>
Success #stdin #stdout 0.03s 25912KB
stdin
Standard input is empty
stdout
Standard output is empty