By using this site you agree to the use of cookies and related technologies.

Learn more

Function Arguments in PHP

This tutorial explains how to use function arguments in PHP.

Edited: 2016-09-24 04:14

Function Arguments can be used to pass information to functions, which will then be handled or acted upon by the code within the function.

If the function is contained within a class, the choice is often between using class variables (properties) or function arguments. It can often be a better solution to use properties, since the data to be passed to the functions will often also be used by other functions. It is also harder to call a function (method) that has arguments, then a calling a fonction that simply uses the properties of a class.

Single Argument

To pass something on to a function, use the below:

function ContentAd($Arg){
// validation

echo '<div class="Advertisement">'. $Arg .'</div>';


The $Arg variable, will contain the content, of whatever you pass on to the function.

These Arguments allow you to do many different things, one example would be, to take user submitted links, and inclose them properly in anchor tags.

  // First define the Function
function ContentAd($Arg){
// validation

echo '<div class="Advertisement">' . $Arg . '</div>';


<html lang="en">

  <title>My first Website</title>


  // Then call the Function somewhere else in the Script.

  $content = '<a href="">Beamtic Tutorials</a>';




The above would still output the same, but this time the link was passed on to the function.

Multiple Arguments

You can use multiple arguments by separating them with a comma (,).

function ContentAd($Arg1, $Arg2){
// validation

echo '<div class="Advertisement">'. $Arg1 .' - '. $Arg2 .'</div>';


Comma is also used when calling the Function.

ContentAd($etc1, $etc2);

Strings and integers

You can also use Strings and integers as arguments, an example is shown below.

ContentAd('String', 144);