Something like this should work:
$myString = '{1}*{2}';
$myValues = [1 => '684', 2 => '42'];
$myFormula = preg_replace_callback('{([0-9]+)}', function($match) use ($myValues) {
return $myValues[$match] ?: 'undefined';
}, $myString);
echo "Resulting formula: $myFormula";
Might want to give a harder error when an undefined index is used, but essentially this should work with some tweaking.
Also if you run a older PHP version than 5.4 you would need to rewrite the short array syntax and the lambda.