

The basic syntax of creating a custom function can be give with:Įxample Run this code » $count, 'values' => $items) The following section will show you how easily you can define your own function in PHP. Functions can be reused in other application - Because a function is separated from the rest of the script, it's easy to reuse the same function in other applications just by including the php file containing those functions.Therefore, fixing errors becomes much easier. The main difference between the print and echo statement is that echo does not behave like a function whereas print behaves like a. It is also a language construct, so we may not use parenthesis i.e print or print (). Functions makes it easier to eliminate the errors - When the program is subdivided into functions, if any error occur you know exactly what function causing the error and where to find it. PHP print statement: The PHP print statement is similar to the echo statement and can be used alternative to echo many times.Functions makes the code much easier to maintain - Since a function created once can be used many times, so any changes made inside a function automatically implemented at all the places without touching the several files.Now you can perform the same task by calling this function wherever you want within your script without having to copy and paste the same block of code again and again. Functions reduces the repetition of code within a program - Function allows you to extract commonly used block of code into a single component.Here are some advantages of using functions:

It is a way to create reusable code packages that perform specific tasks and can be kept and maintained separately form main program. In addition to the built-in functions, PHP also allows you to define your own functions. Please check out PHP reference section for a complete list of useful PHP built-in functions. PHP has a huge collection of internal or built-in functions that you can call directly within your PHP scripts to perform a specific task, like gettype(), print_r(), var_dump, etc.

PHP Built-in FunctionsĪ function is a self-contained block of code that performs a specific task.
PHP ECHO IN SHOWHIDE FUNCTION EXAMPLE HOW TO
In this tutorial you will learn how to create your own custom functions in PHP.
