![]() ![]() ![]() Count and print values in nested arrayĮcho $result. 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. 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.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. Unlike some other language constructs, echo does not have any return value, so it cannot be used in the context of an expression. Its arguments are a list of expressions following the echo keyword, separated by commas, and not delimited by parentheses. Please check out PHP reference section for a complete list of useful PHP built-in functions. echo is not a function but a language construct. 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. ![]() In this tutorial you will learn how to create your own custom functions in PHP. ![]()
0 Comments
Leave a Reply. |