Last active
October 10, 2018 18:13
-
-
Save Cvetomird91/e81c574d5e35f8475adac7114fe6be4a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//the Thesaurus PHP task from Test Dome | |
class Thesaurus | |
{ | |
private $thesaurus; | |
function Thesaurus($thesaurus) | |
{ | |
$this->thesaurus = $thesaurus; | |
} | |
public function getSynonyms($word) | |
{ | |
$synonims = (!empty($this->thesaurus[$word]) ? $this->thesaurus[$word] : array()); | |
return json_encode(array('word'=>$word, 'synonyms'=>$synonims)); | |
} | |
} | |
$thesaurus = new Thesaurus( | |
array | |
( | |
"buy" => array("purchase"), | |
"big" => array("great", "large") | |
) | |
); | |
echo $thesaurus->getSynonyms("big"); | |
echo "\n"; | |
echo $thesaurus->getSynonyms("agelast"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why don't you use the following shortcut, that is supported since php7: