Passing Multiple Variables Into PHP Function


Passing Multiple Variables Into PHP Function

When you pass multiple variables into a PHP function, they can be used within the function. The main point here is the order. You should always input the variables in the same order as you will use them in the function. Naming has nothing to do with it.

The example below shows how to pass multiple variables into a function and how to output those variables.
    
//variables    
$var="Hello";
$var2="World";
//calling function
my_function($var, $var2);

//function below
//Note that the variable $var is now $my_var and $var2 is now $my_var2
my_function($my_var, $my_var2){
    echo $my_var." ".$my_var2;//Outputs Hello World
                }