wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PHP

Total questions: 23

Worksheet time: 14mins

Name
Class
Date
1.

Which tag is used for php

a)

<?php

?>

b)

<style>

c)

<php ?>

d)

<php

/php>

2.

<?php

function add()

{

global $a=10;

echo $a;

}

add();

$a+=10;

?>

Output is?

a)

10

b)

15

c)

20

d)

30

3.

<?php

echo str_replace("world", "Dolly", "Hello world!");

?>

Outputs?

a)

Hello world

b)

Hello Dolly

c)

Error

d)

Hello

4.

What does PHP stands for?

a)

PHP: Hypertext Preprocessor

b)

Private Home Page

c)

Personal Hypertext Processor

5.

Which among the following is the correct delimiters that surround PHP server scripts?

a)

<?php>...</?>

b)

<script>...</script>

c)

<?php...?>

d)

<&>...</&>

6.

How do you write "Hello World" in PHP

a)

Document.Write("Hello World");

b)

"Hello World";

c)

echo "Hello World";

7.

All variables in PHP start with which symbol?

a)

$

b)

!

c)

&

8.

What is the correct way to add 1 to the $count variable?

a)

$count =+1

b)

$count++;

c)

++count

d)

count++;

9.

What will this code do?

<html>

<head>

<title>My First PHP Page</title>

</head>

<body>

<?php

echo "Hello World!";

?>

</body>

</html>

a)

Print the date

b)

Print the time

c)

Print 'Hello World'

d)

None of the above

10.

Complete the following :

<? PHP

_____ "Hi";

?>

a)

echo

b)

php

c)

/html

11.

Each PHP statement must end with a semicolon.

Which symbol is this?

a)

:

b)

,

c)

;

d)

#

12.

Which of the following is the correct syntax?

a)

echo "(<p> Hello.</p>);

b)

echo (<p>' Hello.'</p>);

c)

echo "<p> Hello.</p>";

13.

This code below is missing some simple PHP. Complete the Script

<? php

echo "Hi there, I'm learning some cool PHP Jazz";

_____

a)

<html>

b)

echo

c)

?>

d)

</html>

14.

A PHP variable must start with ?

a)

_

b)

;

c)

$

d)

<

15.

Variable names are case-sensitive.

a)

TRUE

b)

FALSE

16.

Is variable assigned correctly ?

$12num;

a)

TRUE

b)

FALSE

17.

Is variable assigned correctly

$_namasurname;

a)

TRUE

b)

FALSE

18.

<?php

$name = 'John';

$age = '25';

echo $name;

?>


What are the variable ?

a)

<?php

?>

b)

$name

$age

c)

John

25

d)

echo

$name;

19.

A variable declared outside a function has a global scope

a)

TRUE

b)

FALSE

20.

<?php

$t = date("H");


if ($t < "10") {

echo "Have a good morning!";

} elseif ($t < "20") {

echo "Have a good day!";

} else {

echo "Have a good night!";

}

If the current hour is 14, what is an output?

a)

Have a good day!

b)

Have a good night!

c)

Have a good morning

d)

Error

21.

What is the output for the following

<?php

$x = 1;


while($x <= 5) {

echo "The number is: $x <br>";

$x++;

}

?>

a)

0

1

2

3

4

b)

1

2

3

4

5

c)

The number is 1

d)

The number is 1

The number is 2

The number is 3

The number is 4

The number is 5

22.

What should be added to output $i as long as $i is less than 6.

$i = 1;


________________($i < 6) {

echo $i;

$i++;

}

a)

while

b)

for

c)

if

d)

foreach

23.

Create a loop that runs from 0 to 9.

____($i = 0; $i < 10; ____) {

echo $i;

}

(a)