<?php foreach($formula as $key=>$value) { ?>
<?php
$data = $item;
<?php if ($data['dopvopremgost'] == 2){ ?>
$data['lr1P'] = ($data['lr1l']+$data['lr1w'])*2;
$data['lr1SF'] = $data['lr1l']*$data['lr1w'];
$data['lr1SWALL'] = $data['lr1P']*$data['lr1h'];
<?php } ?>
<?php if ($data['dopvopremgost'] == 3){ ?>
$data['rr1P'] = ($data['rr1l']+$data['rr1w'])*2;
$data['rr1SF'] = $data['rr1l']*$data['rr1w'];
$data['rr1SWALL'] = $data['rr1P']*$data['rr1h'];
<?php } ?>
<?php if ($data['dopvopremgost'] == 4){ ?>
$data['or1P'] = ($data['or1l']+$data['or1w'])*2;
$data['or1SF'] = $data['or1l']*$data['or1w'];
$data['or1SWALL'] = $data['or1P']*$data['or1h'];
<?php } ?>
eval('$formula_res = '.$value.';');
?>
<?php } ?>
<?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 . ';');
}
<?php foreach($formula as $key=>$value) { ?>
.....
<?php } ?>
<?php foreach($formula as $key=>$value) : ?>
.....
<?php endforeach; ?>