Passing Variables and Values Into PHP Functions


Using Parameters with PHP Functions

With PHP functions, you can pass variables and strings into a function. Then, the function uses the variables within the function.

Passing variables Into PHP Functions

function my_function($var1, $var2, $var3) {
echo $var 1;
echo $var2;
echo $var3;

}

$variable1="Hello";
$variable2="World";
$variable3="Hello There!";

my_function($variable1, $variable2, $variable3);

#Output Is: HelloWorldHelloThere.
 

Passing Values Into PHP Functions

function my_function($var1, $var2, $var3) {
echo $var 1;
echo $var2;
echo $var3;

}

my_function("Hello", "World", "Hello There");

#Output Is: HelloWorldHelloThere

Passing Values and Variables Into PHP Functions

function my_function($var1, $var2, $var3) {
echo $var 1;
echo $var2;
echo $var3;

}

$variable1="Hello";
$variable2="World";

my_function($variable1, $variable2, "Hello There");

#Output Is: HelloWorldHelloThere

Passing Optional Values Into PHP Functions

function my_function($var1, $var2, $var3='') {
echo $var 1;
echo $var2;
echo $var3;

}

$variable1="Hello";
$variable2="World";
$variable3= $_GET['myvalue'];

my_function($variable1, $variable2, $variable3);

#Output Is: HelloWorldHelloThere.