ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming»
  • Programming Languages

PHP Code Sample Output on While Loop

Updated on April 9, 2013

PHP code, sample PHP Scripts, PHP code example on while loop

Another PHP code example for php programming. Loop in php is similar also to other programming languages. This hub will contain a sample code and a sample output on how while loop works in PHP programming.

Note.: before you continue, if you wish to learn more about php, you should know at a least, how to run a php file on your browser. If you do not know how it us done, please refer to the link below.

How to run a PHP code on your own browser using XAAMP and Notepad++

Please save the following code as whileloop.php, to avoid confusion on running this code.

PHP Code Example on While Loop


	$sum = 0;
	$num = 0;
		$sum = $sum + $num;	
		$product = $product * $num;
	echo "The sum of the numbers from 1 to 10 is: ".$sum. "<br />";
	echo "The product of the numbers from 1 to 10 is: ".$product;

Sample output for whileloop.php

A Beginners' Guide on Running the code:

1. Install XAAMP and Notepad++.

2. Open XAAMP and run the Apache as well as MY SQL on the XAAMP interface.

3. Copy and paste the "php code example in while loop" in notepad++ and save on the drive where you installed the Xaamp, then look for the Xaamp folder, open it, next open the htdocs folder and php file as whileloop.php.

4. After doing that, go to your browser and type this in the address bar: localhost/whileloop.php, the sample output should be similar as the output above.


    0 of 8192 characters used
    Post Comment

    • aisha91 profile image

      Rasna Aisha 5 years ago from Manila, Philippines

      Glad you find it interesting :)

      Thank you for rating it Patty Kenyon.

    • Patty Kenyon profile image

      Patty Kenyon 5 years ago from Ledyard, Connecticut

      Interesting and Useful Information!! Thanks for sharing your code!!