PHP recursive, static variable, anonymous function use

Source: Internet
Author: User
 
    current to-do List !--? php function make_list ($parent        ) {Global $tasks;        Echo ' 
  
    ';            foreach ($parent as $task _id = + $todo) {echo "
   
  • $todo"; if (Isset ($tasks [$task _id])) {//If the current ID has subtasks, the menu make_list is created recursively ($tasks [$task _id]); } echo "
  • "; } Echo '; } $db = Mysqli_connect (' 192.168.31.172 ', ' root ', ' root ', ' phpadvanced '); Mysqli_query ($db, "Set names UTF8"); $q = ' SELECT task_id, parent_id, task from the Tasks WHERE date_completed= ' 0000-00-00 00:00:00 ' ORDER by parent_id, date_added ASC '; $r = Mysqli_query ($db, $q); $tasks = Array (), while (list ($task _id, $parent _id, $task) = Mysqli_fetch_array ($r, Mysqli_num)) {$tasks [$parent _id][$t ASK_ID] = $task;} Echo '
     '; Make_list ($tasks [0]); Send the array containing the top-level task to it, the top parent_id is 0?> 
    !--? php//Create the array.//array structs//studentid =--> ["Name" = "name", "grade" + = XX.X]; $students = [[' Name ' = ' Jon ', ' grade ' = ' 98.5 '], 2 = [' name ' = ' = ' Vance ', ' Grade ' =&G T ' 85.1 ', 9 = [' Name ' = ' Stephen ', ' grade ' = ' 94.0 '], 364 = [' name ' = ' Steve ', ' Grade ' and ' 85.    1 '], [' name ' = ' Rob ', ' grade ' = ' 74.6 '],];function name_sort ($x, $y) {static $count = 1;    echo "

    Iteration $count: {$x [' name ']} vs. {$y [' name ']}

    \ n"; $count + +; return strcasecmp ($x [' name '], $y [' name ']);} function Grade_sort ($x, $y) {static $count = 1; echo "

    Iteration $count: {$x [' Grade ']} vs. {$y [' Grade ']}

    \ 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);?
     
      ["Name" = "name", "Grade" + xx.x]; $students = [[    ' name ' = ' Jon ', ' grade ' = '] ' 98.5 '],    2 =& Gt [' Name ' = ' Vance ', ' grade ' = ' 85.1 '],    9 = [' Name ' = ' Stephen ', ' grade ' = ' 94.0 '],    364 = [' Name ' + ' Steve ', ' grade ' = ' 85.1 '],    [' name ' = ' Rob ', ' grade ' = ' 74.6 '],];echo print_r ($studen TS, 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);? >
     
      

    The above describes the PHP recursion, static variables, anonymous function use, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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