Creating Dynamic Web Sites Part 3 Chapter 3 Creating Dynamic Web Sites Part 3
functions function function_name( ){ // function code. }
Reasons for a function To associate repeated code with one function call. To separate out sensitive or complicated processes from other code. To make common code bits easier to reuse.
index.php Script 3.7 on page 96 http://csweb.hh.nku.edu/csc301/frank/ch03/index.php ch03\index.php
Function Arguments function print_hello($first, $last) { // Function code } print_hello(‘Andy’,’Dalton’); $surname=‘Dalton’; print_hello(‘Andy’,$surname);
calculator.php Script 3.8 on page 98-99 http://csweb.hh.nku.edu/csc301/frank/ch03/script_03_08/calculator.php ch03\script_03_08\calculator.php
Default Argument Values function greet($name, $msg=‘Hello’){ echo “$msg, $name”; } greet($username, $message); greet(‘Zoe’); greet(‘Sam’, ‘Good evening’);
calculator.php Script 3.9 on page 101-103 http://csweb.hh.nku.edu/csc301/frank/ch03/script_03_09/calculator.php ch03\script_03_09\calculator.php
Return Values from a Function function find_sign($month, $day ){ // function code. return $sign; } $mysign = find_sign(‘October’, 23); echo find_sign(‘October’, 23);
calculator.php Script 3.10 on page 105-107 http://csweb.hh.nku.edu/csc301/frank/ch03/calculator.php ch03\calculator.php