Php Sorting Algorithm instance analysis and Sorting Algorithm instance analysis

Source: Internet
Author: User

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.

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.