wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Intro to PHP

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which tag is used for php

a)

<?php

?>

b)

<style>

c)

<php ?>

d)

<php

/php>

2.

$a="deepan";

$b="Deepan";

if(strcmp($a,$b))

{

echo "equal";

}

else{

echo " not equal";}

Output is

a)

Equal

b)

Not equal

c)

Error

d)

None

3.

What is the output of the PHP code.

<?php

$a=0;

$a = 5>2 ?$b=6 : $b=8;

print("$a $a");?>

a)

6

b)

66

c)

68

d)

88

4.

Websites that contain PHP coding have what file extension?

a)

index.html

b)

index.php

c)

index.htmlphp

d)

index.ppt

5.

When concatenating strings, you use what symbol in PHP?

a)

A comma ,

b)

A plus sign +

c)

a hyphen -

d)

a full stop .

6.

What symbol represents the name for a variable?

a)

$variable

b)

#variable

c)

!variable

d)

?variable

7.

PHP is a ............

a)

Open Source Language

b)

Widely Used Language

c)

Server side scripting language

d)

All of the above

8.

Which of the following is the correct way of defining a variable in PHP?

a)

$variable name = value;

b)

$variable_name = value;

c)

$variable_name = value

d)

$variable name as value;

9.

Find the output

<?php

$x = 5;

{ $x = 10;

echo $x;

}

echo $x;

?>

a)

105

b)

510

c)

1010

10.

What is the Output


<?php

$color=red;

echo "$color";

?>

a)

red

b)

$color

c)

No answer

d)

Error

11.

Which of the following is the correct code snippet for a foreach statement in PHP?

a)

foreach ($variable as $key => $value)

b)

foreach ($variable => $key as $value)

c)

foreach ($ctr = 0; $ctr < $array_size; $ctr++)

d)

foreach ($variable => $key => $value)

12.

Identify the invalid short hand assignment operator?

a)

+=

b)

-=

c)

=*

d)

/=

13.

<?php


$i = 0;


while ($i<=5) {

echo $i. " ";

$i++;

}


?>

output for the above code is:

a)

0 1 2 3 4 5

b)

0

1

2

3

4

5

c)

1

2

3

4

5

d)

1 2 3 4 5

14.

Which of the following function is used to get length of a string?

a)

size()

b)

strlen()

c)

length

d)

None of the above

15.

What is the output of the PHP code.

<?php

if(4>5)

{print("Hurray..");}

print("yes");

?>

a)

yes

b)

hurray..yes

c)

Hurray..Yes

d)

none of the above