PHP recursive, static variable, anonymous function use

Source: Internet
Author: User
<!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)!

  • 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.