Passing A Variable Into PHP Functions


Passing Variable Into PHP Functions

When you pass a variable($myvar) into a PHP function, it can be used within the function. The example below shows how to pass a variable into a function and how to output that variable.

$var="Hello";
//To call a function, you simply use the function name and put the variable you want to pass in parenthesees
my_function($var);
function my_function($my_new_var) {
    echo $my_new_var; //Outputs Hello
    }