<?php
 
class Kamus 
{
	private $data = [];
 
	public function tambah($word, $synonyms)
	{
		foreach($synonyms as $s)
		{
			if($s === $word)
			{
				continue;
			}
			$this->link($word, $s);
			$this->link($s, $word); // two-way relation
		}
	}	
 
	public function ambilSinonim($word)
	{
		if(!isset($this->data[$word]))
		{
			return null;
		}
		return array_keys($this->data[$word]);
	}
 
	private function link($a, $b)
	{
		if (!isset($this->data[$a])){
			$this->data[$a] = [];
		}
		$this->data[$a][$b] = true;
	}
}
 
function show($dictionary, $word)
{
	$result = $dictionary->ambilSinonim($word);
	if($result === null)
	{
		echo "* `$word` → `NULL`\n";
	}
	else
	{
		echo "* `$word` → `[" . implode(', ', $result) . "]`\n";
	}
}
 
$kamus = new Kamus();
$kamus->tambah('big', ['large', 'great']);
$kamus->tambah('big', ['huge', 'fat']);
$kamus->tambah('huge', ['enormous', 'gigantic']);

show($kamus, 'big');
show($kamus, 'huge');
show($kamus, 'gigantic');
show($kamus, 'colossal');