Step-by-step tutorials for PHP functions

Source: Internet
Author: User
Use variables to store function names, which are written in the form of variables () when called. This article is mainly to share with you the PHP function advanced explanation, hope to help everyone.

Applicable situation:

This is used when calling different functions, depending on the type of user feedback information.
Instance:

$funf = ' test '; $funf ();

function internal Call function external variable

Use use Keywords

Instance

function test () {    $msg = "I ' m message.";    Get the variable    $say = function ($STR) using the Use keyword (& $msg) {        echo $msg;          Echo ' 

Bubble sort

The so-called bubble sort is to throw the array parameters from small to large or from large to small.

Instance:

From small to large example//define an array $arr = [1,3,2,10,8,7,9];//bubble sort main function Sortarr ($arr) {    //outer traversal, in fact, is to specify how many times the loop for    ($i =0; $i <count ($arr); $i + +) {        //start traversing from the i+1 parameter and traverse for the same        number of times for ($j = $i +1; $j <count ($arr); $j + +) {            //Compare the inner and outer layers            if ($arr [$i] > $ arr[$j]) {                //The value of the inner layer is assigned to the temporary variable                $temp = $arr [$j];                Swap position                $arr [$j] = $arr [$i];                Then assign a value back from the temporary variable                $arr [$i] = $temp;}}    }  Returns the sorted array return  $arr;} Print_r (Sortarr ($arr));

Resources:

Related recommendations:

JavaScript function Advanced Learning and high-level function instance code

Related Article

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.