Php Sorting Algorithm instance analysis and Sorting Algorithm instance analysis
This article analyzes the php sorting algorithm. We will share this with you for your reference. The details are as follows:
Using PHP to write and sort data. Although PHP Automatically sorts data in many ways, SQL statements can quickly read data from the database in an orderly manner. However, different requirements are flexible.
Use the basic PHP knowledge.
I want to complete the following results:
Sorting Algorithm
That is, the data in a value is sorted by time and displayed by branch.
<? Php $ array = $ mysql-> query_array ($ mysql-> SQL _select ("user", "userid, truename, year ","")); // read data from the database $ year = array (); // set an empty array foreach ($ array as $ value) {array_push ($ year, $ value [2]); // import the time data in the data array into the stack} $ year = array_unique ($ year); // remove the repeated data in the array usort ($ year, "strnatcmp "); // sort the data in the array by the natural number $ num = count ($ year); // The number of data in the statistical data/* processing function */function isyear ($ value, $ array) {$ user = array (); // create an empty array foreach ($ arr Ay as $ val) {if ($ val [2] ==$ value) {array_push ($ user, $ val) ;}} return $ user; // returns an array}?>
The above word count processing function. The following shows some codes.
<? Phpfor ($ I = 0; $ I <$ num; $ I ++) {echo "<div class = 'box _ user'> "; echo "<div class = 'boxleft'> {$ year [$ I]} session </div>"; echo "<div class = 'boxright'> "; $ user = isyear ($ year [$ I], $ array); foreach ($ user as $ v) {echo "<span class = {$ v [0] }>{$ v [1] }</span>" ;}echo "</div> "; echo "</div>" ;}?>
The data display code should be easy to understand. I will not write comments in one line here.
In this way, we can get the effect we need. Don't think this is all done .. This is just the first step to abstract the actual problem into code. I don't know how it works?
We can use timestamps to calculate the page loading data time and use PHP automatic functions.
<?php memory_get_usage();?>
To calculate the memory occupied by the Running code.