Parameters / Return Values

Last updated

What is Parameters / Return Values?

Parameters in PHP functions specify the input that the function expects to receive when it is called. They can be of various types like strings, integers, arrays, or even objects. PHP also supports default values for parameters and passing by reference. In PHP, the 'return' statement is often used to end the execution of a function and send back a value. Return values can be any data type. Here's a simple example:

function addNumbers($num1, $num2) {
  $sum = $num1 + $num2;
  return $sum;
}

echo addNumbers(3, 4);  // Outputs: 7

In the above code, $num1 and $num2 are parameters, and the sum of these numbers is the return value.

Free resources to learn Parameters / Return Values

More in stage 5: Functions

Parameters / Return Values: common questions

Can I learn Parameters / Return Values 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 Parameters / Return Values 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 Parameters / Return Values tutorial for beginners?

It is lesson 31 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.

Still confused? Ask me