Q:

PHP: Using one portion of a multidimensional object

I am using an API to return synonyms for a given word.  For example, for the word "funny", I have returned:
Array ( [adjective] => stdClass Object ( [syn] => Array ( [0] => amusing [1] => comic [2] => comical [3] => laughable [4] => mirthful [5] => risible [6] => curious [7] => odd [8] => peculiar [9] => queer [10] => rum [11] => rummy [12] => singular [13] => fishy [14] => shady [15] => suspect [16] => suspicious ) [sim] => Array ( [0] => humorous [1] => humourous [2] => ill [3] => questionable [4] => sick [5] => strange [6] => unusual ) ) [noun] => stdClass Object ( [syn] => Array ( [0] => funny story [1] => good story [2] => funny remark [3] => gag [4] => jape [5] => jest [6] => joke [7] => laugh ) ) )

The thing is, I only need to find the synonyms, which in this case would be:
print_r($synonyms->adjective->syn);

The problem is that the word may not alway be an "adjective", so it may change to something like:
$synonyms->noun->syn;

How to I bypass the first level of this object and just use something like:
$synonyms->syn; // I only want the synonyms

.... something that would work no matter what type of word it is? 
The format will always be $synonyms->type_of_word->syn;

A:

You can just walk through the $synonyms array and for each key (type_of_word) you can check if it has syn peer.  I don't know if, in case of more types have syn defined, you want to merge them all into the result or take just the first one, but you can easily modify the snippet below (it will merge all synonyms from all peers that have syn defined):
$result = array();
foreach ($synonyms as $type) {
    if (isset($type->syn)) {
        $result = array_merge($result, $type->syn);
    }
}

print_r(array_unique($result));

