Home > php教程 > php手册 > body text

PHP1到100求和各种实例程序

WBOY
Release: 2016-06-13 10:17:16
Original
1617 people have browsed it

本文章来给各位同学收藏了一些不错的PHP1到100求和各种实例程序,希望对大家有所帮助。

PHP1到100求和方法集锦,有很多方法都可以实现,先讲一下最简单的几种方法,比如用FOR,WHILE等循环语句求和

FOR循环语句1到100求和方法

 代码如下 复制代码
$sum=0;
for($i=1;$i $sum+=$i.'
';
}
echo $sum;
?>

WHILE循环语句1到100求和方法

 代码如下 复制代码
$i=1;
$sum=0;
while ($i $sum = $sum +$i;
$i++;
}
echo $sum;
?>

DO-WHILE循环语句1到100求和方法

 代码如下 复制代码
$i=1;
$sum=0;
do{
$sum+=$i;
$i++;
}
while ($i echo $sum;
?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!