Php combination sorting simple implementation method, php combination sorting
This example describes how to implement php composite sorting. We will share this with you for your reference. The details are as follows:
Today, I was entangled in a group sorting for one night. Maybe I didn't start to turn around, so I didn't expect to use two stacks. With two stacks, you can easily achieve the desired results.
Combined sorting imaginary chart
In order to do this, I am confused. I first combined the query with SQL, and the result was a combination, but the effect could not be reached. Now paste the PHP code
// Obtain the student information private function ground ($ data) {$ stu = array (); // create a student ID stack, store student ID foreach ($ data as $ key => $ value) {if (in_array ($ value ["studentid"], $ stu )) // determine whether the student ID has been stored {array_push ($ array [$ value ["studentid"], $ value ["selectbh"]); // array_push ($ array [$ value ["studentid"], $ value ["taskid"]); // stack entry} else {// dynamically creates a student information stack. $ Array [$ value ["studentid"] = array ($ value ['selectbh'], $ value ['taskid']); array_push ($ stu, $ value ["studentid"]); // No student ID in the student ID stack} unset ($ stu); // cancel student ID stack return $ array; // return student information node}
With the above code, we can achieve what we want, and preview this page to get the following results
array(2) { ["10408400227"] => array(4) { [0] => string(1) "1" [1] => string(1) "4" [2] => string(1) "2" [3] => string(1) "5" } ["10408400229"] => array(6) { [0] => string(1) "1" [1] => string(1) "4" [2] => string(1) "2" [3] => string(2) "28" [4] => string(1) "3" [5] => string(2) "14" }}
A two-dimensional array is formed, and the student ID is used as the key of the array. In this way, the student ID is associated and you can get the correct one.