Welcome to Egypt Forums Mark forums read | Egypt Main Page
Egypt Forums
Arabic Movies



Classes & Source Code Thread, Functions in PHP in PHP; Functions in PHP Functions are arguably one of the most useful features of PHP. They allow a programmer to encapsulate ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6986


Reply
 
 
The God Father
Developer's Avatar

Reply With Quote
 
Join Date: Jul 2008
Location: NDC
Posts: 5,425
04-12-2008, 04:16 AM
 
Functions in PHP


Functions are arguably one of the most useful features of PHP. They allow a programmer to encapsulate sections of code within a structure which can then be executed from anywhere else in the program flow. Functions are instantiated by use of the function keyword, followed by the user-defined function name including a list of parameters between the paretheses (but we’ll worry about that in a moment) and the body of the function is contained between braces. Just as when defining variables, specific naming conventions must be adhered to. A function name can contain letters, numbers and underscores, and must not start with a number. They are also, like variables, case-sensitive. A (very simple) example:
PHP Code:
function my_function(){
  echo
"Hello world";
  
$a = 5;
  echo
"The value of \$a is $a";
}
my_function();   Hello world
The value of $a is 5


  • Line 1 : The definition of the function. This declares that you, the programmer, have decided to create a function for use called “my_function”. The empty brackets () will be filled in later, but they are important and you cannot leave them out.
  • Lines 2-4 : Inside the braces you can place whatever code you desire
  • Line 6 : This is a function call and lets PHP know that we want to execute the function at this point. This differs from the function declaration in that we are not using the function keyword to create a function. This function call can occur anywhere within the code, as long as it occurs after the function has been declared
__________________
I Love Walking In The Rain Cuz Nobody Know I'm Crying !!
 
 
 
Reply

Classes & Source Code Thread, Functions in PHP in PHP; Functions in PHP Functions are arguably one of the most useful features of PHP. They allow a programmer to encapsulate ...

Short Link: http://forum.egypt.com/enforum/showthread.php?t=6986


Bookmarks

Tags
functions, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Functions (II) Developer Classes & Source Code 0 04-09-2008 10:24 PM
Functions (I) Developer Classes & Source Code 0 04-09-2008 10:23 PM