Code reuse and functions for PHP

Source: Internet
Author: User
 '; 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 ' \ n "; $value =next ($data); } echo "
". $value."
";} $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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.