A function is just a name we give to a block of code that can be executed whenever we need it. This might not seem like that big of an idea, but believe me, when you understand and use functions you will be able to save a ton of time and write code that is much more readable!
This is how you make a function :D.
Open up notepad, or what ever you use to write your php,
PHP Code:
<?php
function hello() {
echo "hello world";
}
hello();
?>
On the first line we start the php, then on the second line we create the function "hello()", on the third line we write what the function will do, then on the fourth line we call up the function, and on the last line we close the php, Ok now if you were to execute that you should see "hello world';.
Ok now lets say we wanted it to hello to what ever name we type in :D, so this is ho we do it
PHP Code:
<?php
function hello($name) {
echo "hello $name";
}
hello("nameyouwanttoputin");
?>
Ok so now on line 2 we added a variable, then on like 3 we echo $name, then on line 5 we execute the function with "nameyouwanttoputin", Ok so what happens is when you execute the function "hello" and put something in bweeten the (), you define $name, So if you were to exeucte hello(), it should say "nameyouwanttoputin", or what ever yoyu put bweeten the () on the 5th line.
You could do as many variables as you like,
PHP Code:
<?php
function hello($name, $lastname) {
echo "hello $name $lastname";
}
hello("HotelUnder", "Seige");
?>
Ok so we put in 2 variables, then on the 5th line we defined them, it would echo hello HotelUnder Seige, So that was simple enough right? Well hope it helped :D