Junior — Middle
How is procedure definition and execution carried out in PHP?
sobes.tech AI
Answer from AI
In PHP, procedures are defined using functions. To create a function, the keyword function is used, followed by the function name and parentheses with parameters (if any). The body of the function is enclosed in curly braces.
Example of defining and calling a function:
function greet($name) {
echo "Hello, $name!";
}
greet('World'); // Outputs: Hello, World!
Functions in PHP can return values using the return keyword. The function is called by its name with the necessary arguments passed.