PHP addition increment operation method 1+2+3+4+5 ..... ......

Source: Internet
Author: User

<?php//while Loop statement













$a =1;//Results

$c Number of =2;//cycles

while ($c <=10) {

$b = $c; Assign the value of C to B

$a = $a + $b;//implement A+b result assignment to a a=3

$c ++;//variable c plus 1, the original 2 becomes 3.

echo "$a"; Output A in loop

echo "<br>";


echo "$a"; Last Output a


The following Do....while loop statements


$a = 1; variable, the result of adding

$b =2;//summand Variable

do {

$a = $a + $b; The result of A+b is assigned to a

$b + +; B plus 1

echo "$a"; Outputs the value of the result variable a once per loop

echo "<br>";//newline Displays the value of each loop output

} while ($b <=100); Condition is false exit loop

echo "$a";//if the output here shows a result


This article is from the "Lu Weizing blog" blog, make sure to keep this source

PHP addition increment operation method 1+2+3+4+5 ..... ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.