How To Pass an Argument to a Function


How To Pass an Argument to a Function? - PHP Script Tips - Creating Your Own Functions



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

2007-04-24, 4594👍, 0💬