NEW
Font size
WorksheetsWeb-II-Loop and Function
Total questions: 10
Worksheet time: 15mins
What will be the output of the following PHP code ?
<?php
$i = 0;
for ($i)
{
print $i;
}
?>
0
infinite loop
no output
error
What will be the output of the following PHP code ?
<?php
for ($x = 1; $x < 10;++$x)
{
print "*\t";
}
?>
**********
*********
***********
infinite loop
What will be the output of the following PHP code ?
<?php
for ($x = -1; $x < 10;--$x)
{
print $x;
}
?>
123456789101112
12345678910
1234567891011
infinite loop
What will be the output of the following PHP code ?
<?php
$x;
for ($x = -3; $x < -5; ++$x)
{
print ++$x;
}
?>
-3-4-5
-3-4
no output
infinite loop
What will be the output of the following PHP code ?
<?php
for ($x = 1; $x < 10; $x++)
for ($y = 1; $y < 5; $y++)
print "Hello";
?>
Hello....36 times
Hello....45 times
Hello....50 times
Hello....40 times
What will happen in this function call?
<?php
function calc($price, $tax)
{ $total = $price + $tax;
}
$pricetag = 15;
$taxtag = 3;
calc($pricetag, $taxtag);
?>
Type Hinting
Default Argument Value
Call By Value
Call By Reference
What will be the output of the following PHP code?
<?php
function calc($price, $tax="")
{
$total = $price + ($price * $tax);
echo "$total";
}
calc(42);
?>
error
0
42
84
What will be the output of the following PHP code?
<?php
function a()
{
function b()
{
echo 'I am b';
}
echo 'I am a';
}
a();
a();
?>
I am b
I am bI am a
Error
I am a Error
What will be the output of the following PHP code?
<?php
function foo($msg)
{ echo "$msg";
}
$var1 = "foo";
$var1("will this work");
?>
Error.
$msg
0
will this work
What will be the output of the following PHP code ?
<?php
$i = 0
do
{ print "hi";
$i++;
}
while ($i != 3);
?>
hi hi
hi
hi hi hi hi
no output
