<分区>
基本的 PHP。我决定打印一个 17.5 的 10 倍数的列表,例如:
17.5 | 35 | 52.5 | 70 | 87.5 | 105 | 122.5 | 140 | 157.5 | 175 |
所以我首先使用了这个循环:
<?php
$number = 17.5;
$result = 0;
$i = 0;
while ($i < 10) {
$result += $number;
echo $result.' | ';
$i++; }
嗯,它有效。然后我切换到这个,它更短:
$i = 1;
$result = 17.5;
while ($i <= 10) {
echo $result * $i.' | ';
$i++; }
但我确信有更好的方法。什么是最好的语法?