$arr = array( 'id' => 1, 'pid' => 0, 'title' => '1', 'id' => 2, 'pid' => 0, 'title' => '2', 'id' => 3, 'pid' => 0, 'title' => '3', 'id' => 4, 'pid' => 0, 'title' => '4', 'id' => 5, 'pid' => 1, 'title' => '1-5', 'id' => 6, 'pid' => 5, 'title' => '1-5-6', 'id' => 7, 'pid' => 1, 'title' => '1-7', 'id' => 8, 'pid' => 2, 'title' => '2-8', );
Finish sorting effect
$arr = array( 'id' => 1, 'pid' => 0, 'title' => '1', 'id' => 5, 'pid' => 1, 'title' => '1-5', 'id' => 6, 'pid' => 5, 'title' => '1-5-6', 'id' => 7, 'pid' => 1, 'title' => '1-7', 'id' => 2, 'pid' => 0, 'title' => '2', 'id' => 8, 'pid' => 2, 'title' => '2-8', 'id' => 3, 'pid' => 0, 'title' => '3', 'id' => 4, 'pid' => 0, 'title' => '4', );
is the parent node immediately following the child node
Reply content:
$arr = array( 'id' => 1, 'pid' => 0, 'title' => '1', 'id' => 2, 'pid' => 0, 'title' => '2', 'id' => 3, 'pid' => 0, 'title' => '3', 'id' => 4, 'pid' => 0, 'title' => '4', 'id' => 5, 'pid' => 1, 'title' => '1-5', 'id' => 6, 'pid' => 5, 'title' => '1-5-6', 'id' => 7, 'pid' => 1, 'title' => '1-7', 'id' => 8, 'pid' => 2, 'title' => '2-8', );
Finish sorting effect
$arr = array( 'id' => 1, 'pid' => 0, 'title' => '1', 'id' => 5, 'pid' => 1, 'title' => '1-5', 'id' => 6, 'pid' => 5, 'title' => '1-5-6', 'id' => 7, 'pid' => 1, 'title' => '1-7', 'id' => 2, 'pid' => 0, 'title' => '2', 'id' => 8, 'pid' => 2, 'title' => '2-8', 'id' => 3, 'pid' => 0, 'title' => '3', 'id' => 4, 'pid' => 0, 'title' => '4', );
is the parent node immediately following the child node
!--? Php$arr = array (' ID ' =--> 1, ' pid ' = + 0, ' title ' = = ' 1 '), array (' id ' = = 2, ' pid ' = + 0, ' title ' = ' 2 '), array (' id ' = = 3, ' pid ' = 0, ' title ' =&G T ' 3 '), array (' id ' = = 4, ' pid ' = + 0, ' title ' = ' 4 '), array (' id ' = = 5, ' pid ' = 1, ' title ' => ; ' 1-5 '), array (' id ' = = 6, ' pid ' = + 5, ' title ' = ' 1-5-6 '), array (' id ' = 7, ' pid ' = = 1, ' title ' = = ' 1-7 '), array (' id ' = = 8, ' pid ' = 2, ' title ' = ' 2-8 '), function userSort ($a, $b) {$a = $ a[' title ']; $b = $b [' title ']; if ($a = = $b) return 0; Return $a > $b? 1:-1;} Usort ($arr, ' userSort '); echo " ";p rint_r ($arr);