wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Web-II-Loop and Function

Total questions: 10

Worksheet time: 15mins

Name
Class
Date
1.

What will be the output of the following PHP code ?

<?php

$i = 0;

for ($i)

{

print $i;

}

?>

a)

0

b)

infinite loop

c)

no output

d)

error

2.

What will be the output of the following PHP code ?

<?php

for ($x = 1; $x < 10;++$x)

{

print "*\t";

}

?>

a)

**********

b)

*********

c)

***********

d)

infinite loop

3.

What will be the output of the following PHP code ?

<?php

for ($x = -1; $x < 10;--$x)

{

print $x;

}

?>

a)

123456789101112

b)

12345678910

c)

1234567891011

d)

infinite loop

4.

What will be the output of the following PHP code ?

<?php

$x;

for ($x = -3; $x < -5; ++$x)

{

print ++$x;

}

?>

a)

-3-4-5

b)

-3-4

c)

no output

d)

infinite loop

5.

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";

?>

a)

Hello....36 times

b)

Hello....45 times

c)

Hello....50 times

d)

Hello....40 times

6.

What will happen in this function call?

<?php

function calc($price, $tax)

{ $total = $price + $tax;

}

$pricetag = 15;

$taxtag = 3;

calc($pricetag, $taxtag);

?>

a)

Type Hinting

b)

Default Argument Value

c)

Call By Value

d)

Call By Reference

7.

What will be the output of the following PHP code?

<?php

function calc($price, $tax="")

{

$total = $price + ($price * $tax);

echo "$total";

}

calc(42);

?>

a)

error

b)

0

c)

42

d)

84

8.

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();

?>

a)

I am b

b)

I am bI am a

c)

Error

d)

I am a Error

9.

What will be the output of the following PHP code?

<?php

function foo($msg)

{ echo "$msg";

}

$var1 = "foo";

$var1("will this work");

?>

a)

Error.

b)

$msg

c)

0

d)

will this work

10.

What will be the output of the following PHP code ?

<?php

$i = 0

do

{ print "hi";

$i++;

}

while ($i != 3);

?>

a)

hi hi

b)

hi

c)

hi hi hi hi

d)

no output