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.