Nested Loops with Same max values in PHP
Notes:
PHP Nested Loops :
- If required we can place one loop inside another loop, which is called as nesting of loops.
Case 1: loops with same max values, also called as quadratic loops
for($=0; $i<n; $i++)
{
for($j=0; $j<n; $j++)
{
sequence of statement(s); // n x n times
}
}
Ex: 1
for($i=0; $i<2; $i++)
{
for($j=0; $j<2; $j++)
{
echo("Hello World <br/>"); // 2 x 2 = 4 times
}
}
Ex: 2
for($i=0; $i<3; $i++)
{
for($j=0; $j<3; $j++)
{
echo "Hello World","<br/>"; // 3 x 3 = 9 times
}
}
Interview Questions:
1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a