PHP –如何编写基于7个值生成派对费用表的代码?
因此,例如,如果min是且max是60,cost1是5,cost2是10,cost3是15,cost4是20,cost5是25
这应该是一个好的开始。
//the (int) changes the input to an integer, which will help prevent code injection.
//$_GET takes variables from the URL string, like http://google.com?min=30&max=60
//$_POST takes variables from a form on the page that then gets submitted <input type="text" name="min" value="30" />
$min = (int) $_GET['min'];
$max = (int) $_GET['max'];
$costs = array(
'5',
'10',
'15',
'20',
'25',
);
echo '<table>';
for($i = $min; $i <= $max; $i++)
{
//if the number is divisible by 5, show it in the table
if($i % 5 === 0)
{
echo '<tr>';
echo '<td>' . $i . '</td>';
foreach($costs as $cost)
{
echo '<td>' . $cost . '<br>' . $cost * $i . '</td>';
}
echo '</tr>';
}
}
echo '</table>';
结果表将是:
30150300450600750
35175350525700875
等等...直到60(包括)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句