PHP Functions

In the world of programming and scripting there are two ways to write code. One way is to write long, sprawling and monolithic sections of script. Another is to break the scripts up into tidy, self contained modules that can be re-used without having to re-invent the same code over and over again.
Obviously the latter is highly preferable to the former, and the fundamental building block of this approach to writing PHP scripts is the function.
Similar to other programming languages, such as C/C++/Java/JavaScript/etc., PHP provides a way for programmers to define functions, which can then be called elsewhere in the program.
A function is a block of code that can be executed whenever we need it. A function is just a name we give to a block of code that can be executed when needed
Functions are basically named scripts that can be called upon from any other script to perform a specifc task. Values (known as arguments) can be passed into a function so that they can be used in the function script, and functions can, in turn, return results to the location from which they were called.
PHP functions exist it two forms, functions that are provided with PHP to make your life as a web develeper easier, and those that you as a web developer create yourself.
Scroll to Top