Php code reuse and functions

Source: Internet
Author: User
: This article mainly introduces php code reuse and functions. For more information about PHP tutorials, see.
 '; Require ('reusable. php'); echo 'The script will end now.
'; // Function declaration function my_function () {echo 'My function was called';} my_function (); // use the 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 two', 'line three '); create_table ($ my_array); // scope keyword 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 transfer and value transfer: address operator & function increment (& $ value, $ amount = 1) {$ value = $ value + $ amount ;} $ a = 10; echo $.'
'; Increment ($ a); echo $ .'
'; // Return keyword: terminate the function execution function larger ($ x, $ y) {if ((! Isset ($ x) | (! Isset ($ y) {echo "This function requires two numbers.
"; Return;} if ($ x >=$ y) {echo $ x ."
";} Else {echo $ y ."
";}}$ A = 1; $ B = 2.5; $ c = 1.9; larger ($ a, $ B); larger ($ d, $ ); // return keyword: return a value from the function. 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, $ ).'
'; // 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 the php Manual-functions

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces php code reuse and functions, including some content, and hopes to help those who are interested in PHP tutorials.

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.