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'); // sortForeach (\$ 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 statisticsForeach (\$ 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 Keywords:
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Apsara Conference 2019

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

Alibaba Cloud Free Trial

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