Php recursion, static variables, anonymous functions

Source: Internet
Author: User
: This article mainly introduces php recursion, static variables, and anonymous functions. For more information about PHP tutorials, see.
    
     Current To-Do List
 '; Foreach ($ parent as $ task_id => $ todo) {echo"
  • $ Todo "; if (isset ($ tasks [$ task_id]) {// if the current id has subtasks, recursively create the menu make_list ($ 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 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] [$ task_id] = $ task;} // echo'
    '.print_r($tasks,1).'
    '; Make_list ($ tasks [0]); // sends an array containing top-level tasks to it. The top-level parent_id is 0?>
     ["Name" => "Name", "grade" => xx. x]; $ students = [256 => ['name' => 'Jon ', 'grade' => '98. 5'], 2 => ['name' => 'vance ', 'Grad' => '85. 1 '], 9 => ['name' => 'Stephen', 'Grad' => '94. 0'], 364 => ['name' => 'Steve ', 'Grad' => '85. 1 '], 68 => ['name' => 'Rob', 'Grad' => '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 ['Grad']} vs. {$ y ['Grad']}

    \ N "; $ count ++; return $ x ['grade '] <$ y ['grade'];} echo print_r ($ students, 1 ); uasort ($ students, 'Name _ sort '); // keep the key and use the custom sorting echo print_r ($ students, 1); uasort ($ students, 'grade _ sort '); echo print_r ($ students, 1);?>
     ["Name" => "Name", "grade" => xx. x]; $ students = [256 => ['name' => 'Jon ', 'grade' => '98. 5'], 2 => ['name' => 'vance ', 'Grad' => '85. 1 '], 9 => ['name' => 'Stephen', 'Grad' => '94. 0'], 364 => ['name' => 'Steve ', 'Grad' => '85. 1 '], 68 => ['name' => 'Rob', 'Grad' => '74. 6'],]; echo print_r ($ students, 1); uasort ($ students, function ($ x, $ y) {return strcasecmp ($ x ['name'], $ y ['name']) ;}); // keep the key and use custom sorting Echo print_r ($ students, 1); uasort ($ students, function ($ x, $ y) {return $ x ['grade '] <$ y ['grade'];}); echo print_r ($ students, 1);?>
     

    The above describes the use of php recursion, static variables, and anonymous functions, including some content. I hope to be helpful to anyone interested in PHP tutorials.

    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.