[PHP] Tutorial Five Basic Functions 02-21-2013, 03:37 AM
#1
A function is just a neat way to call a script. This isn't the best way to explain but that's how I see it.
So let me give you an example on how to make and call a function
This is how you would change the value of $number1 and $number2 without having to change the code.
Note: If you need any help and I have not yet made a tutorial for it please visit php.net.
So let me give you an example on how to make and call a function
PHP Code:
<?PHP
echo function_name(); //This will echo out the function.
function function_name(){ //This is starting the function.
$number1 = 1;
$number2 = 2;
$number3 = $number1 + $number2;
return $number3; //To return the data back you need to put return then the data you want to return back!
}
?>This is how you would change the value of $number1 and $number2 without having to change the code.
PHP Code:
<?PHP
$number1 = 1;
$number2 = 2;
echo function_name($number1, $number2); //As you see we are putting the strings in to the function.
function function_name($number1, $number2){ //This is where you put the strings names to be called in the function.
$number3 = $number1 + $number2;
return $number3; //To return the data back you need to put return then the data you want to return back!
}
?>Note: If you need any help and I have not yet made a tutorial for it please visit php.net.


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)





![[Image: BAvhP6h.png]](http://i.imgur.com/BAvhP6h.png)