Passing an Argument to a Function in PHP


How To Pass an Argument to a Function? in PHP?



To pass an argument to a function, you need to:

  • Add an argument definition in the function definition.
  • Add a value as an argument when invoking the function.

Here is a PHP script on how to use arguments in a function():

function f2c($f) {
  return ($f - 32.0)/1.8;
print("Celsius: ".f2c(100.0)."\n");
print("Celsius: ".f2c(-40.0)."\n");

This script will print:

Celsius: 37.777777777778
Celsius: -40


Creating Your Own Functions in PHP

⇒⇒PHP Tutorials

2016-12-24, 294👍, 0💬