Bird
0
0

What is the correct way to declare a function named greet in PHP?

easy📝 Conceptual Q11 of 15
PHP - Functions
What is the correct way to declare a function named greet in PHP?
Afunction greet() { }
Bdef greet() { }
Cfunc greet() { }
Dfunction: greet() { }
Step-by-Step Solution
Solution:
  1. Step 1: Recognize PHP function declaration syntax

    In PHP, functions are declared using the keyword function followed by the function name and parentheses.
  2. Step 2: Match the correct syntax

    function greet() { } uses function greet() { }, which is the correct PHP syntax for declaring a function named greet.
  3. Final Answer:

    function greet() { } -> Option A
  4. Quick Check:

    PHP function declaration = function greet() { } [OK]
Quick Trick: Use 'function' keyword to declare functions in PHP [OK]
Common Mistakes:
  • Using 'def' instead of 'function'
  • Adding a colon after 'function'
  • Using 'func' keyword which is not valid in PHP

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes