Skip to content
doubtly

How to define a function in PHP? a) functionName(parameters) {function body} b) function {function body}

How to define a function in PHP?
a) functionName(parameters) {function body}
b) function {function body}
c) function functionName(parameters) {function body}
d) data type functionName(parameters) {function body}
Doubtly Asked Updated Student doubt Save WhatsApp Report

2 answers

Answer: c) function functionName(parameters) {function body}

In PHP a function is defined with the keyword function, followed by its name, the parameter list and the body:

<?php
function add($a, $b) {
    return $a + $b;
}
echo add(2, 3);   // 5
?>

Option (a) has no function keyword, (b) has no name or parameters, and (d) uses a data type before the name as in C or Java, which PHP syntax does not use.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.