Здравствуйте. Можно ли как то оптимизировать этот код что бы не писать "простыню"? PHP: <?php $sum1=$_REQUEST['select1']+$_REQUEST['select16']+$_REQUEST['select31']+$_REQUEST['select46']+$_REQUEST['select61']+$_REQUEST['select76']; $sum2=$_REQUEST['select2']+$_REQUEST['select17']+$_REQUEST['select32']+$_REQUEST['select47']+$_REQUEST['select62']+$_REQUEST['select77']; $sum3=$_REQUEST['select3']+$_REQUEST['select18']+$_REQUEST['select33']+$_REQUEST['select48']+$_REQUEST['select63']+$_REQUEST['select78']; $sum4=$_REQUEST['select4']+$_REQUEST['select19']+$_REQUEST['select34']+$_REQUEST['select49']+$_REQUEST['select64']+$_REQUEST['select79']; $sum5=$_REQUEST['select5']+$_REQUEST['select20']+$_REQUEST['select35']+$_REQUEST['select50']+$_REQUEST['select65']+$_REQUEST['select80']; $sum6=$_REQUEST['select6']+$_REQUEST['select21']+$_REQUEST['select36']+$_REQUEST['select51']+$_REQUEST['select66']+$_REQUEST['select81']; $sum7=$_REQUEST['select7']+$_REQUEST['select22']+$_REQUEST['select37']+$_REQUEST['select52']+$_REQUEST['select67']+$_REQUEST['select82']; $sum8=$_REQUEST['select8']+$_REQUEST['select23']+$_REQUEST['select38']+$_REQUEST['select53']+$_REQUEST['select68']+$_REQUEST['select83']; $sum9=$_REQUEST['select9']+$_REQUEST['select24']+$_REQUEST['select39']+$_REQUEST['select54']+$_REQUEST['select69']+$_REQUEST['select84']; $sum10=$_REQUEST['select10']+$_REQUEST['select25']+$_REQUEST['select40']+$_REQUEST['select55']+$_REQUEST['select70']+$_REQUEST['select85']; $sum11=$_REQUEST['select11']+$_REQUEST['select26']+$_REQUEST['select41']+$_REQUEST['select56']+$_REQUEST['select71']+$_REQUEST['select86']; $sum12=$_REQUEST['select12']+$_REQUEST['select27']+$_REQUEST['select42']+$_REQUEST['select57']+$_REQUEST['select72']+$_REQUEST['select87']; $sum13=$_REQUEST['select13']+$_REQUEST['select28']+$_REQUEST['select43']+$_REQUEST['select58']+$_REQUEST['select73']+$_REQUEST['select88']; $sum14=$_REQUEST['select14']+$_REQUEST['select29']+$_REQUEST['select44']+$_REQUEST['select59']+$_REQUEST['select74']+$_REQUEST['select89']; $sum15=$_REQUEST['select15']+$_REQUEST['select30']+$_REQUEST['select45']+$_REQUEST['select60']+$_REQUEST['select75']+$_REQUEST['select90']; ?> PHP: <table width="250" border="1" cellspacing="0" cellpadding="0"> <tr> <th scope="col"><span class="table2">Касб номи: -></span></th> <th scope="col">Касбга қизиқиши:</th> </tr> <?php if($sum1>0){echo '<tr> <td><span class="table2">Физика</span></td> <td> '.$sum1.'</td> </tr>';}?> <?php if($sum2>0){echo '<tr> <td><span class="table2">Математика</span></td> <td>'.$sum2.'</td> </tr>';}?> <?php //.... //.... //.... //.... //.... ?> <?php if($sum15>0){echo '<tr> <td><span class="table2">Спорт</span></td> <td>'.$sum15.'</td> </tr>';}?>
можно PHP: <?php $indexes = array('1'=>array(1,6,31,46,61,76),.....,'15'=>array(5,30,45,60,75,90)); foreach ($indexes as $key => $value) { $var = "sum$key"; $$var = 0; foreach ( $value as $key1 => $value1) { $$var += $_REQUEST['select'.$value1]; } }