usort($array, function($a, $b) {
return $a - $b; // or something, y'know, more complex.
});
$text = preg_replace_callback('/\((\d+)\+(\d+)\)/', function($match) {
return '(' . ($match[1] + $match[2]) . ')';
}, '(2+3) (10+7)');
// (5) (17) but i didn't test this at all.
Basically...