Очеловечу ваш код:
<?php
foreach ($formula as $key => $value) {
$data = $item;
$prefixGroups = array(
'dopyyyy' => array(2 => 'yy'),
'dopvopremgost' => array(2 => 'lr', 3 => 'rr', 4 => 'or'),
'dopdopvopsuvsid' => array(2 => 'zz'),
);
foreach (array_keys($prefixGroups) as $key => $prefixes) {
if (array_key_exists($data[$key], $prefixes)) {
$prefix = $prefixes[$data[$key]];
$data[$prefix . '1P'] = ($data[$prefix . '1l'] + $data[$prefix . '1w']) * 2;
$data[$prefix . '1SF'] = $data[$prefix . '1l'] * $data[$prefix . '1w'];
$data[$prefix . '1SWALL'] = $data[$prefix . '1P'] * $data[$prefix . '1h'];
}
}
eval('$formula_res = ' . $value . ';');
}