# For Loop/PHP

george
For Loop/PHP
Posted in : PHP

Write a class called math. It is to have one property called num. It also has one method called factorial. This method is to start at 1 and multiply all of the integers to num. If num is 5 then you would multiply 12345. How would you write this as a loop? Would I need to use the for loop or do/while loop?

September 27, 2012 at 11:28 AM

PHP Factorial Example:

```<?php
\$n = 5;
\$i = 1;
\$f = 1;
while(\$i<\$n){
\$i = \$i + 1;
\$f = \$f * \$i;
}
echo \$f;
?>
```

September 27, 2012 at 11:29 AM

Here is a java example that finds the factorial of a number.

```public class math{
public static long factorial(int n){
if(n <= 1)
return 1;
else
return n * factorial(n - 1);
}
public static void main(String [] args){
int num=5;
System.out.println(factorial(num));
}
}
```

for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
for( ) loop in php
for( ) loop in php  Generally, when we use for loop in PHP or any other programming language why we use i++ and not ++i. What is the reason behind
foreach loop in php
foreach loop in php  Foreach loop in php
How to call Array Length for loop in PHP
How to call Array Length for loop in PHP  Hello, I am learner in PHP scripting Language. How can I use the array length for loop in PHP programming language? Kindly provides online help guide or reference links. Thanks
For Loop/PHP
12345. How would you write this as a loop? Would I need to use the for loop or do/while loop?   PHP Factorial Example: <?php \$n = 5; \$i = 1; \$f...For Loop/PHP  Write a class called math. It is to have one property
foreach Loop
foreach Loop In PHP, for & foreach loop executes code block a specific number of times, or until condition fails. The for Loop The for loop executes... to loop. Given below the example : <html> <body> <?php
PHP FORM Part-8
is false. The syntax for a while loop in PHP is : initialize = value; ...Topic : HTML FORM While Loop Part - 8 In this part of tutorial, we will learn about the While loop. Instead of using for loop, we can also use while loop
php array foreach/how to use foreach loop to iterate and print all the values in an array
Foreach is enhanced version of the for loop. It is used to iterate through the array elements. It is used only with the array. Example of PHP Array Foreach Loop <?php \$ar1=array("mango","apple","orange","grapes
while & do..while Loop
while & do..while Loop while loop The while loop iterate until provided...; <?php \$j=1; while(\$j<=3) { echo "Value of j" . \$j . "<... loop always executes its block of code at least once. Given below the syntax
php array loop count
php array loop count  Count the array using loop in php
PHP While Loop
While Control Structure: While is the simplest form of loop. While loop checks..., and become infinite loop. While loop is also known as pre-test loop. Basic format of while loop is as follows: while(condition) expressions
php do while syntax
php do while syntax  How to create a do while loop in php. What is the syntax
php do while example
php do while example  Simple example of do while loop in PHP
php do while loop
php do while loop  Difference between do while loop and simple loop in PHP
php array loop key value
php array loop key value  How to use Array key value loop in PHP
php while loop
php while loop  Example to fetch the data using while loop in PHP
PHP Do While Loop
Do-While Loop Function PHP: PHP Do-While loop method is another type of loop which runs at least once, since this loop checks the condition after executing... of the variable within the loop. PHP do while loop Example: <?php \$i=34; do
PHP Regular Expression
& POST PHP Loop PHP Arrays PHP Strings PHP Date...PHP regular expression allows programmer to perform various task like... strings. PHP Regular expression also allows you to validate a email, phone
PHP While Loop
While Loop in PHP: In programming language we need to use loops for executing... Loop in PHP: While loop checks the condition first and if it is true... loop.     PHP While Loop Example: <?php \$i=1
PHP For Each Loop Function
Foreach Loop in PHP In PHP  associative array gives us more power to use... you to learn for each loop precisely: Example: <?php \$studentClass.... To fetch values from associative array we need to use for each loop. Using
PHP For Each Loop
Foreach Loop in PHP In PHP  associative array gives us more power to use... to learn for each loop precisely: Example: <?php \$studentClass... loop. Using  for each loop we can assign values of one by one