計數結果如何,我們從For循環如何從For循環
$starting_year=2001;
$ending_year=2015;
for ($x = $starting_year; $x <= $ending_year;$x++) {
echo "$x <br />";
}
算結果我怎麼算一代?例如上面應該是5
計數結果如何,我們從For循環如何從For循環
$starting_year=2001;
$ending_year=2015;
for ($x = $starting_year; $x <= $ending_year;$x++) {
echo "$x <br />";
}
算結果我怎麼算一代?例如上面應該是5
嘗試這樣得到與的發生次數爲 循環,但我也有像你爲什麼需要爲循環這裏從去年開始只是減去一年級的值以得到一個問題代
$starting_year = 2001;
$ending_year = 2015;
$generation = 0;
for ($x = $starting_year; $x <= $ending_year; $x++) {
echo "$x <br />";
$generation++;
}
echo "No of generation $generation";
希望它會幫助你,
<?php
$starting_year = 2001;
$ending_year = 2015;
$count = 0;
for ($x = $starting_year; $x <= $ending_year; $x++) {
$count++;
}
echo $count;
?>
你並不需要一個循環。
試試這個:
<?php
$starting_year=2001;
$ending_year=2015;
$generation = $ending_year - $starting_year;
echo $generation;
?>
我在評論中添加了相同內容:) – RJParikh
爲什麼你需要的循環? '$ ending_year - $ starting_year'還不夠? –
'$ count = $ ending_year - $ starting_year'因此'$ count = 2015 - 2001' Ans是'$ count = 14' – RJParikh