<?php

class Kamus {
    private $data = array();
    
    public function tambah($kata, $sinonim) {
        if (!isset($this->data[$kata])) {
            $this->data[$kata] = array();
        }
        foreach ($sinonim as $s) {
            if (!isset($this->data[$s])) {
                $this->data[$s] = array();
            }
            if ($s === $kata) {
                continue;
            }
            if (!in_array($s, $this->data[$kata], true)) {
                $this->data[$kata][] = $s;
            }
            if (!in_array($kata, $this->data[$s], true)) {
                $this->data[$s][] = $kata;
            }
        }
    }

    public function ambilSinonim($kata) {
        return isset($this->data[$kata])
            ? $this->data[$kata]
            : null;
    }
}

$kamus = new Kamus();

$kamus->tambah('big', array('large', 'great'));
$kamus->tambah('big', array('huge', 'fat'));
$kamus->tambah('huge', array('enormous', 'gigantic'));
echo json_encode($kamus->ambilSinonim('big')) . "\n";
echo json_encode($kamus->ambilSinonim('huge')) . "\n";
echo json_encode($kamus->ambilSinonim('gigantic')) . "\n";
echo json_encode($kamus->ambilSinonim('colossal')) . "\n";