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