Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PHP Quiz - 1

Total questions: 75

Worksheet time: 1hrs 17mins

Name
Class
Date
1.

What type of language is PHP

a)

Client Side

b)

Server Side

c)

Browser Side

d)

Web Side

2.

PHP is executed on

a)

The Server

b)

The Browser

c)

The Website

d)

The Machine

3.

We create re-usable code blocks by placing them inside?

a)

Variables

b)

Parameters

c)

Code Blocks

d)

Functions

4.

Sometimes we only want certain code to execute if a condition is true. How do we test for that?

a)

Loop

b)

If Statement

c)

Integer

d)

Variable

5.

What is a integer?

a)

It's a Whole Number

b)

It's a Decimal Number

c)

It's a True or False Declaration

d)

It's a String of Text

6.

What is a String?

a)

Text

b)

Number

c)

True

d)

Loop

7.

What is a Boolean

a)

It's Just Text

b)

It's a Number

c)

It's Just True

d)

It's True or False

8.

What if we want a block of code to execute several times?

a)

Use a Variable

b)

Use a Function

c)

Use a Loop

d)

Use a Leap

9.

$colours = array("black, blue, Red, Green") - How do I access "Red" ?

a)

$colours[0];

b)

$colours[2];

c)

$colours[1]

d)

$colours[3];

10.

How do I print out the values of the variable "name" ?

a)

$name;

b)

include $name;

c)

echo $name;

d)

echo $name

11.

function sayMyName(name) {} ; - How do I call tat function

a)

sayMyname();

b)

$sayMyName;

c)

$sayMyName();

d)

sayMyName("John")';

12.

What does i++ do ?

a)

Adds the text on to the end of i

b)

Adds i on to the end of something

c)

Adds i on to the existing value of i

d)

Adds 1 to the current value of iThis is a correct answer

13.

What type of variable is this: $isMale = false;

a)

Integer

b)

Boolean

c)

String

d)

char

14.

In an IF statement we can have 2 conditions tested. Which keyword allows this?

a)

Else

b)

if Else

c)

Else if

d)

OR

15.

$a = 4 ; $b = 6; $c = $a + $b; What is the value of variable "c" ?

a)

6

b)

8

c)

10

d)

None

16.

$a = "Ram"; $n = "Kumar"; $fullName = $f + $n; What is the value of $fulName

a)

RamKumar

b)

Ram Kumar

c)

Ram

d)

None

17.

$a = "Ram"; $n = "Kumar"; $fullName = $f . $n; What is the value of $fulName

a)

RamKumar

b)

Ram Kumar

c)

Kumar

d)

None

18.

function declarations can have (a)   assigned to them?

19.

Function calls can have____________ inside them.

a)

Parameters

b)

Arguments

c)

Variables

d)

Types

20.

What

does PHP stand for?

a)

Private

Home Page

b)

Hypertext

Preprocessor

c)

Pretext

Hypertext Processor

d)

Preprocessor

Home Page

21.

Which

of the following function of String object is used to match a regular

expression against a string?

a)

concat()

b)

match()

c)

search()

d)

replace()

22.

Which

one of the following databases has PHP supported almost since the beginning?

a)

Oracle

Database

b)

SQL

c)

SQL+

d)

MySQL

23.

Who is

the father of PHP?

a)

Rasmus

Lerdorf

b)

Willam

Makepiece

c)

Drek

Kolkevi

d)

List

Barely

24.

PHP

files have a default file extension of_______

a)

.html

b)

.xml

c)

.php

d)

.ph

25.

A

function in PHP which starts with __ (double underscore) is known as

__________

a)

Magic

Function

b)

Inbuilt

Function

c)

Default

Function

d)

User

Defined Function

26.

Which

of the below statements is equivalent to $add += $add?

a)

$add =

$add

b)

$add =

$add +$add

c)

$add =

$add + 1

d)

$add =

$add + $add + 1

27.

Client

Side Script executed by ____________

a)

Webserver

b)

IIS

c)

Apache

d)

Browser

28.

A

function name cannot start with a ____

a)

alphabet

b)

underscore

c)

number

d)

Both C

and B

29.

Which

built-in method removes the last element from an array and returns that

element?

a)

last()

b)

get()

c)

pop()

d)

None of

the above.

30.

Why

should we use functions?

a)

Reusability

b)

Easier

error detection

c)

Easily

maintained

d)

All of

the above

31.

Which

of the following function of Array object extracts a section of an array and

returns a new array?

a)

reverse()

b)

shift()

c)

slice()

d)

some()

32.

Comments in PHP are written with ...

a)

$

b)

//

c)

<!-- ... -->

d)

" ... "

33.

The correct way of defining a variable in PHP?

a)

$variable name = value;

b)

$variable_name = value

c)

$variable name as value;

d)

$variable_name = value;

34.

The correct way to print out the values of the variable "name" is ...

a)

$name;

b)

include $name;

c)

echo $name;

d)

echo $name

35.

<?php

$sum= 15+30;

echo "$sum";

?>

The Correct output is ...

a)

Error

b)

15+30

c)

45

d)

No Answer

36.

<?php

$x = 10;

$y = 6;

echo $x % $y;

?>

The correct type of operator in the code above is ...

a)

Arithmetic Operators

b)

Assignment Operators

c)

Comparison Operators

d)

Increment / Decrement Operators

37.

<?php

$number = 20;

if($number < 10){

echo "SMA ABBS";

}else{

$sum = $number + 10;

echo "$sum";

}

?>

The output is ...

a)

SMA ABBS

b)

20

c)

30

d)

Error

38.

<?php

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

echo "$x ";

}

?>

the output is ...

a)

1 2 3 4 5 6 7 8 9 10

b)

10 9 8 7 6 5 4 3 2 1

c)

5 6 7 8 9 10

d)

No answer

39.

What is the correct output of the given code <?php

$NUM1 = 3;

$NUM2 = 4;

$NUM3 = $NUM1 ** $NUM2;

echo $NUM3;

?>

a)

12

b)

81

c)

Garbage Value

d)

None of the above

40.

The "**" operator belongs to which category of operators?

a)

Arithmetic operator

b)

Logical operator

c)

Comparison operator

d)

Conditional operator

41.

Which of the following are comparison operators in PHP?

A. ==

B. !=

C. ===

D. <

a)

A and B

b)

C and D

c)

A,B and C

d)

A,B,C and D

42.

What is the Output?

<?php

#echo "Hello World"

echo "#Hello World";

?>

a)

Hello World #Hello World

b)

Hello World

c)

#Hello World

d)

Error

43.

What is the Output


<?php

$color=red;

echo "$color";

?>

a)

red

b)

$color

c)

No answer

d)

Error

44.

All variables in PHP start with which symbol?

a)

?

b)

$

c)

!

d)

=

45.

How do you create an array in PHP?

a)

$cars = "Volvo", "BMW", "Toyota";

b)

$cars = array["Volvo", "BMW", "Toyota"];

c)

$cars = array("Volvo", "BMW", "Toyota");

46.

What is the Output:

<?php

$color= "red";

echo "$color";

echo "$COLOR";

echo "$Color";

?>

a)

redredred

b)

redred

c)

red

d)

Error

47.

What is the Ouput

<?php

$color1="green";

$color2="yellow";

echo "$color1" + "$color2";

?>

a)

greenyellow

b)

green yellow

c)

Error

d)

0

48.

What is the output?


<?php

define(GREETING, " PHP is a Scripting Language");

echo "$GREETING;

?>

a)

$GREETING

b)

no output

c)

GREETING

d)

PHP is a Scripting Language

49.

<?php

$x=10;

$y=4;

$z=3;

echo ($x % ($y) + $z);

?>

a)

5

b)

3

c)

0

d)

1

50.

What is the Output?

<?php

$four4 =4;

$three3 = 3;

$two2 = 2;

echo " $four4 + $three3 / $two2 - 1"

a)

4.5

b)

7

c)

3.5

d)

Error

51.

PHP server scripts are surrounded by delimiters, which?

a)

<?php...?>  

b)

<?php>...</?>

52.

What is the correct way to create a function in PHP?

a)

new_function myFunction()

b)

create myFunction()

c)

function myFunction()  

53.

PHP allows you to send emails directly from a script

a)

False

b)

True

54.

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

a)

count++;

b)

$count =+1

c)

++count

d)

$count++;  

55.

Which operator is used to check if two values are equal and of same data type?

a)

===  

b)

==

c)

!=

d)

=

56.

By using the PHP, create the following variables

$x=10; $y=7;

Then write code to print out the following:

10 + 7 = 17

10 - 7 = 3

10 * 7 = 70

10 / 7 = 1.4285714285714

10 % 7 = 3

Use numbers only in the above variable assignments, not in the echo statements.

(a)  

57.

Write the output of the code given.

(a)  

58.

Write the output of the code given.

(a)  

59.

What is the correct way to end a PHP statement?

a)

;

b)

</php>

c)

.

d)

New line

60.

In PHP you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings:

a)

FALSE

b)

TRUE

61.

Which superglobal variable holds information about headers, paths, and script locations?

a)

$GLOBALS

b)

$_GET

c)

$_SERVER

d)

$_SESSION

62.

1.

PHP is a _________.

a)

Open Source Language

b)

Widely Used Language

c)

Server side scripting language

d)

All of the above

63.

4.

PHP is case sensitive in what way?

a)

It's never case sensitive, don't worry about it.

b)

Only when referring to variables

c)

When referring to classes, functions or variables

d)

All the time!

64.

7.

What does CRUD operation stands for in PHP?

a)

Create

Read

Upload

Delete

b)

Create

Read

Update

Delete

c)

Concatenate

Read

Update

Destroy

d)

Concatenate

Read

Upload

Delete

65.

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)

66.

What are the two types of array in php

a)

Indexed, sequence

b)

Associative, sequence

c)

Indexed, associative

d)

None

67.

$a=array("Timmy","Jimmy");

Is an example of

a)

Indexed array

b)

Associative array

c)

Sequence array

d)

None

68.

$a=array("Jimmy"=>10,"mummy"=>20);

Is an example of

a)

Sequence array

b)

Indexed array

c)

Associative array

d)

None

69.

function add(&a)

{

$a=10;

echo $a;}

$a=33;

This is an example for

a)

Call by value

b)

Call by reference

c)

Both of the above

d)

None

70.

<?php

function add()

{

global $a=10;

echo $a;

}

add();

$a+=10;

?>

Output is

a)

10

b)

15

c)

20

d)

30

71.

$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

72.
We can use ___ to comment a single line?
i) /?
ii) //
iii) #
iv) /* */
a)
Only ii)
b)
i), iii) and iv)
c)
ii), iii) and iv)
d)
Both ii) and iv)
73.
Which of the following php statement/statements will store 111 in variable num?
i) int $num = 111;
ii) int mum = 111;
iii) $num = 111;
iv) 111 = $num;
a)
Both i) and ii)
b)
All of the mentioned.
c)
Only iii)
d)
Only i)
74.
What will be the output of the following php code?
 <?php
 $num = 1;
 $num1 = 2;
 print $num . "+". $num1;
 ?>
a)
3
b)
1+2
c)
1.+.2
d)
Error
75.
What will be the output of the following php code?
 <?php
 $num = "1";
 $num1 = "2";
 print $num+$num1;
 ?>
a)
3
b)
1+2
c)
Error
d)
12