Functions are pieces of script that can be used more then 1 time or in multiple scripts. Let's say you want to check if someone has a valid session ID but don't want to place on every top of your page a code that checks it. Then you can use a function that will replace a 10 line code into a 1 line code that calls for the function !
The normal view of a function is :
Function function-name($Parameter1,$Parameter2,...) {
Some code
}
Example :
functions.inc.php
PHP pastebin - collaborative debugging tool
So this function will check if a session is valid. If the session is valid he will print out logged in, else he will print out Not logged in.
index.php
PHP pastebin - collaborative debugging tool
The output will look like :
Not logged in
logged in!
Why did he change the second line ? Because, as you can see, I have defined the $_SESSION['logged'] to the requested needs to get a true response.
The use of functions can decrease the total size of your pages so a faster load is possible ! Also functions are called Snippets because they aren't a full code. So when you are searching for functions, search for snippets.