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