Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Thesaurus
- {
- private $thesaurus;
- function Thesaurus($thesaurus)
- {
- $this->thesaurus = $thesaurus;
- }
- public function getSynonyms(string $word)
- {
- if($this->thesaurus[$word]) {
- $data = [
- 'word' => $word,
- 'synonyms' => $this->thesaurus[$word]
- ];
- } else {
- $data = [
- 'word' => $word,
- 'synonyms' => []
- ];
- }
- return json_encode($data);
- }
- }
- $thesaurus = new Thesaurus(
- array
- (
- "buy" => array("purchase"),
- "big" => array("great", "large")
- ));
- echo $thesaurus->getSynonyms("big");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement