Php returns the maximum value after sorting two-dimensional arrays.

Source: Internet
Author: User

Custom:

The code is as follows: Copy code

Function array_sort ($ arr, $ keys, $ type = 'asc ') {// 2-dimensional array sorting
$ Keysvalue = $ new_array = array ();
Foreach ($ arr as $ k =>$ v ){
$ Keysvalue [$ k] = $ v [$ keys];
 }
If ($ type = 'asc '){
Asort ($ keysvalue );
} Else {
Arsort ($ keysvalue );
 }
Reset ($ keysvalue );
Foreach ($ keysvalue as $ k => $ v ){
$ New_array [$ k] = $ arr [$ k];
 }
Return $ new_array;
}

Recently, a data analysis system needs to use various sorting methods. Below is a sorting process:

The code is as follows: Copy code

// $ Re is the data source, two-dimensional array

$ Re = $ this-> array_sort ($ re, 'lv', 'desc'); // sort
Foreach ($ re as $ key => $ val ){
Foreach ($ val as $ key2 => $ val2 ){
If ($ key2 = "uid "){
$ Count [] = $ val2; // obtain the total number of created roles
$ Lv [$ val2] [] = $ re [$ key] ['LV']; // Obtain all role levels
   }
    
  }
 }
$ Count = array_count_values ($ count );
Foreach ($ count as $ key => $ val ){
M ()-> query ("update mj_ad_count set create_juese = create_juese +". $ val. "where suid =". $ key );
Echo M ()-> getLastSql ();
 }
Foreach ($ lv as $ key => $ val) {// level check to find the maximum value and write statistics
Foreach ($ val as $ key2 => $ val2 ){
If ($ key2 = 0 ){
// $ Ls [$ key] [] = $ val2;
M ()-> query ("update mj_ad_count set juese_leave =". $ val2. "where suid =". $ key );
Echo M ()-> getLastSql ();
   }   
  }
 }

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.