'; require (' reusable.php '); Echo ' The script would end now.
';//function declaration functions My_function () {echo ' My function was called ';} My_function ()//Use parameter function create_table ($data) {echo '
"; Reset ($data); $value =current ($data); while ($value) {echo '
". $value." |
\ n "; $value =next ($data); } echo "
";} $my _array=array (' line one ', ' line ', ' line Three '); Create_table ($my _array);//Scope Key globalfunction fn () {Global $var ; $var = "Contens 2"; echo "Inside the function,\ $var =". $var. "
";} $var = "Contents 1"; FN (); echo "outside the function,\ $var =". $var. "
";///parameter reference pass and value pass: Address character &function increment (& $value, $amount =1) {$value = $value + $amount;} $a =10;echo $a. '
'; increment ($a); Echo $a. '
';//return keyword: execution function for terminating functions larger ($x, $y) {if ((!isset ($x)) | | (!isset ($y))) {echo "This function requires the numbers.
"; Return } if ($x >= $y) {echo $x. "
"; }else{echo $y. "
"; }} $a =1; $b =2.5; $c =1.9;larger ($a, $b); larger ($d, $a);//return keyword: Returns a value from function smaller ($x, $y) {if (!isset ($x)) | | (!isset ($y))) {return false; }else if ($x <= $y) {return $x; }else{return $y; }}echo smaller ($a, $b). '
'; echo smaller ($d, $a). '
';//implement Recursive function Reverse_r ($str) {if (strlen ($STR) >0) {Reverse_r (substr ($STR, 1)); } Echo substr ($str, 0, 1); return;} function Reverse_i ($STR) {for ($i =1; $i <=strlen ($STR); $i + +) {echo substr ($str,-$i, 1); } return; Reverse_r (' hello '); Echo '
'; reverse_i (' hello ');//phpinfo ();
For more details, refer to PHP manual-functions
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the PHP code reuse and functions, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.