<!doctype html>
Static variable statistic number code
<?php//create the array.//array structs//studentid = > ["name" = = "Name" "," grade "+ xx.x]; $students = [[' Name ' = ' Jon ', ' grade ' = ' 98.5 '], 2 = [' name ' = ' + ' Va nCE ', ' grade ' = ' 85.1 '], 9 = [' Name ' = ' Stephen ', ' grade ' = ' 94.0 '], 364 = [' name ' = ' Steve ' , ' grade ' = ' 85.1 ', [' name ' + ' Rob ', ' grade ' = ' 74.6 '],];function name_sort ($x, $y) {static $ Count = 1; echo "<p>iteration $count: {$x [' name ']} vs. {$y [' name ']} </p>\n"; $count + +; return strcasecmp ($x [' name '], $y [' name ']);} function Grade_sort ($x, $y) {static $count = 1; echo "<p>iteration $count: {$x [' Grade ']} vs. {$y [' Grade ']}</p>\n '; $count + +; return $x [' Grade '] < $y [' Grade '];} Echo Print_r ($students, 1); Uasort ($students, ' name_sort '); Hold key and use custom sort echo print_r ($students, 1); Uasort ($students, ' grade_sort '); Echo Print_r ($students, 1);?
anonymous function--closure code
<?php//Create the array.//array structs//studentid = > ["name" = "name", "Grade" + xx.x]; $students = [
256 = [' name ' = ' Jon ', ' grade ' = ' 98.5 '], 2 = [' name ' = ' Vance ', ' grade ' = ' 85.1 '], 9 =& Gt [' Name ' = ' Stephen ', ' grade ' = ' 94.0 '], 364 = [' name ' = ' Steve ', ' grade ' = ' 85.1 '], [ ' Name ' = ' Rob ', ' grade ' = ' 74.6 '],];echo print_r ($students, 1); Uasort ($students, function ($x, $y) { return STRCASECMP ($x [' name '], $y [' name '];}); Hold key and use custom sort echo print_r ($students, 1); Uasort ($students, function ($x, $y) { return $x [' Grade '] < $y [' Grade '];}); Echo Print_r ($students, 1);? >
Reference to the parameter, when the data is a big data when used, there is no need to copy the data copy of the code
<?phpfunction Increment (& $i) { $i + +;} $num = 2;increment ($num); Echo $num;? >
The above is the PHP recursive, static variables, anonymous function use of content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!