Php array bubble sorting algorithm instance, php array algorithm instance _ PHP Tutorial

Source: Internet
Author: User
Php array bubble sorting algorithm instance and php array algorithm instance. Php array bubble sorting algorithm example, php array algorithm example this article describes the php array bubble sorting algorithm. For your reference, see php * @ bubble sorting algorithm php array bubble sorting algorithm instance and php array algorithm instance.

This article describes the php array bubble sorting algorithm. We will share this with you for your reference. The details are as follows:

<? Php/* @ bubble sorting algorithm */$ array = array (,); $ len = count ($ array ); // calculate the array length for ($ I = 0; $ I <$ len-1; $ I ++) {// you need to compare $ len-1 wheel, each round needs to compare $ len-1 times for ($ j = 0; $ j <$ len-1; $ j ++) {// needs to compare $ len-1 times, because no number can be compared after the loop to the last number, the number of loops to the second to the last is exactly $ k = $ j + 1; // Obtain the subscript of the next number of the current number, we compare the if ($ array [$ j]> $ array [$ k]) values with the subscript 0---4, respectively. {// compare two numbers. if the previous number is greater than the last one, the order of the two numbers is exchanged. $ t = $ array [$ j]; $ array [$ j] = $ array [$ k]; $ array [$ k] = $ t;} // after the first loop comparison, perform the next round of comparison. } Print_r ($ array);/* the key to understanding the bubble sorting is that its comparison result is to put a large number in the future, and the largest and second largest number is obtained in sequence, the third largest number... And so on */?>

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.