wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

FUNCTION PHP

Total questions: 8

Worksheet time: 4mins

Name
Class
Date
1.

What is the purpose of a PHP function?

a)

To store variables

b)

To execute a specific task

c)

To print HTML code

d)

To create classes

2.

Which keyword is used to declare a function in PHP?

a)

method

b)

func

c)

def

d)

function

3.

Which of the following is true about function names in PHP?

a)

They cannot start with a number

b)

They cannot contain special characters

c)

They are case-insensitive

d)

They must always start with a dollar sign ($)

4.

What does the keyword "return" do in a PHP function?

a)

It terminates the function

b)

It echoes a message

c)

It sends a value back to the calling code

d)

It generates an error

5.

Which of the following statements about parameters in PHP functions is true?

a)

Functions cannot accept parameters

b)

Parameters are optional

c)

Parameters are enclosed in curly braces {}

d)

Parameters are placeholders for values passed to the function

6.

What is the purpose of the "global" keyword in PHP functions?

a)

To declare a variable as local to the function

b)

To access a variable declared outside of the function

c)

To define a constant

d)

To include another PHP file

7.

What is the default scope of a PHP function if no scope is specified?

a)

Global

b)

Local

c)

Protected

d)

Private

8.

What is the purpose of the "static" keyword in a PHP function?

a)

To define a constant

b)

To declare a variable as local to the function

c)

To retain the value of a variable between function calls

d)

To include another PHP file