Advertisement
KaueDrey

Teste

Aug 13th, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. class Thesaurus
  4. {
  5.     private $thesaurus;
  6.  
  7.     function Thesaurus($thesaurus)
  8.     {
  9.         $this->thesaurus = $thesaurus;
  10.     }
  11.  
  12.     public function getSynonyms(string $word)
  13.     {
  14.         if($this->thesaurus[$word]) {
  15.             $data = [
  16.                 'word' => $word,
  17.                 'synonyms' => $this->thesaurus[$word]
  18.             ];
  19.  
  20.         } else {
  21.             $data = [
  22.                 'word' => $word,
  23.                 'synonyms' => []
  24.             ];
  25.         }
  26.  
  27.         return json_encode($data);
  28.     }
  29. }
  30.  
  31. $thesaurus = new Thesaurus(
  32.     array
  33.         (
  34.             "buy" => array("purchase"),
  35.             "big" => array("great", "large")
  36.         ));
  37.  
  38. echo $thesaurus->getSynonyms("big");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement