【发布时间】:2015-05-14 00:15:34
【问题描述】:
基本的 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++; }
但我确信有更好的方法。最好的语法是什么?
【问题讨论】:
-
最好的语法是最容易阅读的。
标签: php list loops multiplication