And the structure is always like this?
((word1 word2)(word3 word4))
I'd say first you'd have to get the four words in an array. With preg_match() for example:
$words = preg_match('/\\(\\((.*?) (.*?)\\)\\((.*?) (.*?)\\)\\)/', '((APPLE MANGO)(BALL BAT))');
This will give this result:
 => ((APPLE MANGO)(BALL BAT))
 => APPLE
 => MANGO
 => BALL
 => BAT
So if you ignore the first element, the next four will contain the four words.
Now all you have to do is find the reference object, and swap it with the first object, and then recreate the string.