What is a function?
A function is just a container for a block of code. Functions are powerful because they enable you to create a section of code that can, if well-written, be copied and pasted from program to program saving you writing it each time.
In addition it makes debugging easier as you can track problems to individual blocks of code - the functions.
And also very attractive is that with a function you don't necessarily need to know how it works once written to use it - just like all the built-in functions in PHP, you can make it available to others and they can copy and paste it and it should work.
Here is a simple function in action:
<?php
function myfirstfunction() {
echo "My first function!";
}
myfirstfunction(); // call the function
?>
Comment on this Question and Answer >>>
ASK A QUESTION
More functions PHP Questions
WHAT IS THE CORRECT WAY TO OPEN THE FILE "time.text" AS READABLE?how can i get the data by using get(),post()methods?
Hi; I had an email from my hosting company which said that my account was hacked and one script in images folder is trying to send thousands of spams(file name : "/public_html/images/sm5vy7.php"). they blocked my account and asked me to check
Is there a way to use readfile() and not have it display the byte number at the bottom?
How do I get a variable in a function to retain its value between calls?
