Podcast
Questions and Answers
Which keyword is used to begin a user-defined function declaration in PHP?
Which keyword is used to begin a user-defined function declaration in PHP?
- method
- define
- function (correct)
- subroutine
In PHP, function names are case-sensitive.
In PHP, function names are case-sensitive.
False (B)
How do you call or execute a function in PHP?
How do you call or execute a function in PHP?
Write the function's name followed by parentheses.
Arguments passed to a PHP function are specified inside the __________.
Arguments passed to a PHP function are specified inside the __________.
What does the opening curly brace {
indicate in a PHP function?
What does the opening curly brace {
indicate in a PHP function?
A PHP function will automatically execute when a page loads.
A PHP function will automatically execute when a page loads.
What is the purpose of arguments in a PHP function?
What is the purpose of arguments in a PHP function?
To let a function return a value, use the __________ statement.
To let a function return a value, use the __________ statement.
In PHP, what happens when a function argument is passed by value?
In PHP, what happens when a function argument is passed by value?
You can only pass one argument to a PHP function.
You can only pass one argument to a PHP function.
How do you specify a default value for a function argument in PHP?
How do you specify a default value for a function argument in PHP?
In PHP, to pass an argument by reference, you must use the __________ operator before the variable name in the function definition.
In PHP, to pass an argument by reference, you must use the __________ operator before the variable name in the function definition.
What will be the output of the following PHP code snippet?
function add_five(&$value) { $value += 5; } $num = 2; add_five($num); echo $num;
What will be the output of the following PHP code snippet?
function add_five(&$value) { $value += 5; } $num = 2; add_five($num); echo $num;
The function name must start with an integer.
The function name must start with an integer.
Match the following code with their functionality:
Match the following code with their functionality:
Flashcards
What is a function?
What is a function?
A block of statements that can be used repeatedly.
Creating a Function
Creating a Function
A user-defined function declaration starts with the keyword function
, followed by the function's name.
How to call a function?
How to call a function?
Write its name followed by parentheses ()
.
Function Arguments
Function Arguments
Signup and view all the flashcards
Specifying Arguments
Specifying Arguments
Signup and view all the flashcards
Default Argument Value
Default Argument Value
Signup and view all the flashcards
Returning a Value
Returning a Value
Signup and view all the flashcards
Passing by Value
Passing by Value
Signup and view all the flashcards
Passing by Reference
Passing by Reference
Signup and view all the flashcards
Study Notes
PHP Functions
- A function is a block of statements for repeated use in a program.
- Functions do not automatically execute when a page loads, but are executed when called.
Creating Functions
- User-defined function declarations start with the keyword
function
, followed by the function name. - Function names must begin with a letter or an underscore.
- Function names are not case-sensitive.
Calling Functions
- Call a function by writing its name followed by parentheses
()
. - The opening curly brace
{
indicates the start of the function code. - The closing curly brace
}
indicates the end of a function.
Function Arguments
- Arguments pass information to functions, functioning like variables.
- Arguments are specified inside the parentheses after the function name, separated by commas.
Default Argument Value
- A default parameter is used when a function is called without arguments.
- If
setHeight()
is called without arguments, it takes the default value as the argument.
Returning Values
- To return a value from a function, the
return
statement is used.
Passing Arguments by Reference
- Arguments are usually passed by value, meaning a copy of the value is used and the original variable cannot be altered.
- When an argument is passed by reference, changes to the argument also affect the original variable.
- To pass an argument by reference, the
&
operator is used.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.