Function Declaration
Last updated
What is Function Declaration?
Function is the block of code that performs a specific task. It is a reusable code that can be called multiple times. In PHP, a function is declared using the function keyword followed by the function name and parentheses. The function name should be unique and descriptive. The parentheses may contain parameters that are passed to the function. The function body is enclosed within curly braces {}.
function greeting($name) {
echo "Hello, " . $name;
}
In this case, 'greeting' is the function name, '$name' is the parameter, and 'echo "Hello, " . $name;' is the operation.
Free resources to learn Function Declaration
- Official docsUser Defined Functions
More in stage 5: Functions
Function Declaration: common questions
Can I learn Function Declaration in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain Function Declaration in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this Function Declaration tutorial for beginners?
It is lesson 30 of 120 in the free PHP roadmap, in stage 5, Functions. If you are new to PHP, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.