Need help to optimize code

Here is example of code

<!DOCTYPE HTML><html xmlns="http://www.w3.org/1999/xhtml"><head><title>test</title><meta charset="utf-8" /><style>.aligncenter{text-align:center;}</style></head><body>
    <?
    $bets = array(
      array('rub','10','20','30','50','70'),
      array('usd','0.20','0.40','0.50','0.80','1.25'),
      array('eur','0.15','0.30','0.40','0.65','1.00'),
      array('nis','0.75','1.50','2.00','3.00','5.00')
      );
    $cur = $_GET['cur'];
    if(isset($cur)){
    if($cur == $bets[0][0]){$curnum = 0;$curname = 'Rubl';}elseif($cur == $bets[1][0]){$curnum = 1;$curname = 'Dollar';}elseif($cur == $bets[2][0]){$curnum = 2;$curname = 'Euro';}elseif($cur == $bets[3][0]){$curnum = 3;$curname = 'Shekel';}
    echo "<table><thead><tr><th></th><th></th><th colspan=\"5\">".$curname."</th></tr></thead><tbody><tr><th></th><th></th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<th>".$bets[$curnum][$i]."</th>";
    }
    echo "<tr><td rowspan=\"8\" class=\"aligncenter\">M<br />A<br />T<br />C<br />H</td>";
    echo "<th>0</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*1, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>1</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*0, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>2</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*0, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>3</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*2, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>4</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*5, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>5</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*7, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>6</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*40, 2)."</td>";
    }
    echo "</tr>";
    echo "<th>7</th>";
    for($i = 1; $i <= 5; $i++){
    	  echo "<td class=\"aligncenter\">".number_format($bets[$curnum][$i]*500, 2)."</td>";
    }
    echo "</tr>";
    echo"</tbody></table>";
    }
    ?>
</body></html>

maybe with one ir two for($i = 1; $i <= 5; $i++) or else way to get results like in example. Thanks for help

$names = array("rub" => "Ruble","usd" => "Dollar","eur" => "Euro","nis" => "Shekel");
$bets = array("rub" => array(10,20,30,50,70),"usd" => array(0.2,0.4,0.5,0.8,1.25),"eur" => array(0.15,0.3,0.4,0.65,1), "nis" => array(0.75,1.5,2,3,5));
$multipliers = array(1,0,0,2,5,7,40,500);

 $cur = (in_array($_GET['cur'],array_keys($names)) ? $_GET['cur'] : "rub";
echo "<table><thead><tr><th></th><th></th><th colspan=\"5\">".$names[$cur]."</th></tr></thead><tbody><tr><th></th><th></th></tr><tr><td rowspan=\"8\" class=\"aligncenter\">M<br />A<br />T<br />C<br />H</td></tr>";
for($i = 0; $i < 8; $i++) {
  echo "<tr><th>$i</th>";
  foreach($bets[$cur] AS $value) {
     echo "<td class=\"aligncenter\">".number_format($value*$multipliers[$i], 2)."</td>";
  }
  echo "</tr>";
}
?>
</tbody></table></body></html>

Try this:

$bets2 = array(
  'rub' => array('Rubl', '10','20','30','50','70'),
  'usd' => array('Dollar', '0.20','0.40','0.50','0.80','1.25'),
  'eur' => array('Ruble', '0.15','0.30','0.40','0.65','1.00'),
  'nis' => array('Shekel', '0.75','1.50','2.00','3.00','5.00')
  );
$rates = array(1,0,0,2,5,7,40,500);
$cur   = isset($_GET['cur']) ? $_GET['cur'] : 'usd';

function amounts($x, $y, $cur, $bets2)
{
  echo "\n\r" .'<tr>';
    echo '<th>' .$x .'</th>';
    for($i = 1; $i<6; $i++){
      echo '<td class="aligncenter">' .number_format($bets2[$cur][$i]* $y, 2).'</td>';
    }
  echo '</tr>' ."\n\r";
}

      echo '<div>';  
        echo '<h4>'.$bets2[$cur][0] .'</h4>';
        echo '<div id="match">';
            echo 'M A T C H';
        echo '</div>';

        echo '<table><tr>' ."\n\r";
          echo '<th> </th>';            
          for($i = 1; $i<6; $i++){
            echo '<th>' .$bets2[$cur][$i] .'</th>';            
          }
        echo '</tr>' ."\n\r";

        foreach($rates as $item => $rate){
            amounts($item, $rate, $cur, $bets2);
        }
        echo"</tbody></table>";
      echo '</div>';  

http://www.johns-jokes.com/downloads/sp-d/Alexander_Stiopin/

John_Betong and StarLion thanks you very much! I will check the source code optimization )))

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.