Using Functions in PHP
Overview: This article shows you how to use functions, create your custom functions and how to effectively work with function's in PHP.
|
A function is basically a PHP script designed to accomplish a single task (usually a task that will need to be accomplished multiple times). Furthermore the code contained within functions is ignored until the function is called from another part in the script. |
|
Creating your own function
Functions in PHP begin with the keyword function followed by the function name. This function name must adhere to the same criteria as variables except they do not begin with $ character as other PHP variables do.
function ([$var1 [= constant]],
[$var2 [= constant]], ...) {
}
Creating a simple function
Passing parameters to functions
We have seen how to create functions, now I will show you how to pass some parameters to a functions, A function parameter is nothing more than a piece of data that the function requires to execute.
Functions with default parameters
Can we have a default value as a parameter I mean if I dont specify any value can a function pick up a default value?
Yes we can easily build functions that have default parameters.
Home | Privacy Policy | Contact Us | Terms of Service
(c) 2002 - 2018 www.PHPbuddy.com Unauthorized reproduction/replication of any part of this site is prohibited.
|