PHP Function Lookup:
PHP Quick Start
PHP Installation
PHP Articles
PHP Scripts

Top Rated Articles 

Site Related
Submit Articles/Code
Contact Us
Instant cash loans, cash advance online same day

   Home                   Article Added on: April 8, 2002
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
A function that prints the string "Hello, Functions!" 5 times View Sample Output

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.

Modifying our above example and add parameters to that function View Sample Output

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.

Modifying the example and adding default parameters to that function View Sample Output
Rate this article:  Current Rating: 3.36
  Poor    Excellent     
          1     2    3    4    5


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.