Php combination sorting simple implementation method, php combination sorting

Source: Internet
Author: User

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.

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.