| Share this post! | Vote this! |
|
Before we get started, PHP has well over 400 functions that you can use.
Below are some examples:
count()
preg_replace()
phpinfo()
And many more. So with that said, let's look at the advantages of creating your own custom functions. As you start to create larger projects and you are reusing large chunks of code over and over again which can become time consuming, this is where creating your own custom functions comes to the rescue and saves you a lot of coding time.
For example, what I mean is that I have this very large project and I have throughout the code an error message code snippet that pops up when an error happens like for say every time a field is not filled out in a form and I have many forms that use the same error message again and again. This is where a custom function comes in handy, see example below.
1. if((!$_POST[name]) || (!$_POST[message] || (!$_POST[email]))
{
echo ("A field was left blank please go back and try again.");
}
More...
Below are some examples:
count()
preg_replace()
phpinfo()
And many more. So with that said, let's look at the advantages of creating your own custom functions. As you start to create larger projects and you are reusing large chunks of code over and over again which can become time consuming, this is where creating your own custom functions comes to the rescue and saves you a lot of coding time.
For example, what I mean is that I have this very large project and I have throughout the code an error message code snippet that pops up when an error happens like for say every time a field is not filled out in a form and I have many forms that use the same error message again and again. This is where a custom function comes in handy, see example below.
1. if((!$_POST[name]) || (!$_POST[message] || (!$_POST[email]))
{
echo ("A field was left blank please go back and try again.");
}
More...




0 comments:
Post a Comment