Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP Function Arguments

Information can be passed to functions using arguments, which function similarly to variables.

Arguments are listed after the function name, inside the parentheses. You can include as many arguments as needed, separating them with commas.

In the following example, the function has one argument ($fname). When the familyName() function is called, we also provide a name (e.g., “Jani”), which is used within the function to output several different first names while maintaining the same last name

Example

function familyName($fname) {
  echo "$fname Refsnes.<br>";
}
 
familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");

The following example features a function with two arguments: ($fname, $year):

Example

function familyName($fname, $year) {
  echo "$fname Refsnes. Born in $year <br>";
}
 
familyName("Hege", "1975");
familyName("Stale", "1978");
familyName("Kai Jim", "1983");