creating php pages n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Creating PHP Pages PowerPoint Presentation
Download Presentation
Creating PHP Pages

Loading in 2 Seconds...

  share
play fullscreen
1 / 10
bryant

Creating PHP Pages - PowerPoint PPT Presentation

117 Views
Download Presentation
Creating PHP Pages
An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Creating PHP Pages Chapter 8 PHP Functions

  2. PHP Functions Functions are groups of statements that you can execute as a single unit PHP functions need to be defined with keyword function It can have zero or more values (parameters) Functions may or may not return values If a function need to return value, the last statement of the function should be return return value; The set of curly braces (called function braces) contain the function statements

  3. PHP Functions Function declaration in PHP <?php function name_of_function(parameters) { statements; } ?> for e.g. function sayHello() { echo(“<b>hello<b><br />”); }

  4. PHP Functions Parameter less function <?php function hello() { echo “hi”; } ?> This can be called as <?phphello(); ?> in the program

  5. PHP Functions Parameterized function <?php function greet($name) { echo “Hello “ . $name; } ?> This can be called <?php greet(‘You’);?> This gives an output Hello You

  6. PHP Functions Assigning functions to the variables for e.g $first = “first_func”; to invoke the function first_func() through the variable $first(); When an argument is to be passed by reference, an ampersand (&) is placed before the parameter name for e.g. first_func(&$first_ref);

  7. Returning Values A return statement returns a value to the statement that called the function Not all functions return values function averageNumbers($a, $b, $c) { $SumOfNumbers = $a + $b + $c; $Result = $SumOfNumbers / 3; return $Result; }

  8. Returning Values You can pass a function parameter by value or by reference A function parameter that is passed by value is a local copy of the variable. A function parameter that is passed by reference is a reference to the original variable.

  9. global Keyword In PHP, you must declare a global variable with the globalkeyword inside a function definition to make the variable available within the scope of that function Example : <?php $GlobalVariable = "Global variable"; function scopeExample() { global $GlobalVariable; echo "<p>$GlobalVariable</p>"; } scopeExample(); ?>

  10. References Thank’s to : Blazzard, J. B. (2011). Functions and Control Structures (ppt document). Retrieved from Lecture Notes Online Web site: http://www.lcsc.edu/jblazzar/citpt227/. References : Anonymous.(n.d.). Apache HTTP Server Documentation Version 2.2. Retrieved from http://httpd.apache.org/docs/2.2/. Achour, M., Betz, F. (n.d.), PHP Manual. Retrieved from http://www.php.net/download-docs.php. Anonymous. (n.d.). MySQL Reference Manual. Retrieved from http://downloads.mysql.com/docs/. Naramore, E., Gerner, J., Le Scouarnec, Y., Stolz, J., Glass, M. K. (2005). Beginning PHP5, Apache, and MySQL® Web Development. Indianapolis, IN: Wiley Publishing, Inc.