|
|
|
| Title : |
A simple bubblesort that takes 2 arrays as argument.The first one is the actual data used for sorting, the second is data that will "tag along" with the first array, for instance a descriptive text about the data in the first array. |
| Categories : |
Algorithms, Arrays, PHP, Complete Programs |
 Petter Nilsen |
| Date : |
Jan 17th 1999 |
| Grade : |
3 of 5 (graded 10 times) |
| Viewed : |
15633 |
| File : |
No file for this code example. |
| Images : |
No Images for this code example. |
|
| Search : |
More code by Petter Nilsen |
|
| Action : |
Grade This Code Example
|
|
| Tools : |
My Examples List |
|
|
|
|
|
|
<?php
function bubblesort($a1,$a2)
{
for($i = sizeof($a1); $i >= 1; $i--)
{
for($j = 1; $j <= $i; $j++)
{
if($a1[$j-1] > $a1[$j])
{
$t = $a1[$j-1];
$t2 = $a2[$j-1];
$a1[$j-1] = $a1[$j];
$a2[$j-1] = $a2[$j];
$a1[$j] = $t;
$a2[$j] = $t2;
}
}
}
}
?>
|
|
| A recursive function to traverse a multi-dimensional array where the
dimensions are not known Categories : Arrays, PHP, Algorithms | | | navbar.php3 - Dynamic hyperlinked navigation bars Categories : HTML and PHP, Arrays, PHP, Complete Programs | | | A class to put get and post variables in hidden form
elements. Works on scalars, normal arrays, associative
arrays. Categories : Algorithms, Variables, Arrays, PHP, PHP Classes | | | quick sort for associative arrays Categories : Algorithms, Arrays, PHP | | | minus - subtract arrays. Send two arrays and get an array with the operation A-B, elements on A that are not included on B. Categories : PHP, Arrays, Algorithms | | | Browse a MySQL database & draw a tree view & load final items into a template page. Categories : MySQL, Complete Programs, Algorithms, PHP, Databases | | | PHP mySQL learning example This is a complete program to modify tables
in a mySQL database on a nice and neat way. Categories : PHP, MySQL, Complete Programs, HTML and PHP | | | Complete NotePad application for Websites (Like Yahoo Notepad) Categories : PHP, Web Applications, Filesystem, Java Script, Complete Programs | | | phpFreeChat Categories : PHP, AJAX, Complete Programs | | | Filling an array with files from any given directory. This example is for the current PHP script's directory. Categories : PHP, Arrays, Filesystem | | | Automatic banner rotation. Randomly selects a banner for display. Categories : Graphics, PHP, Complete Programs | | | Finds the median in an array of numbers - Can be used with a MySql database column read into an array Categories : PHP, Arrays, Databases, MySQL | | | grab the result of any calculation you submit to the Google Calculator. Categories : PHP, Arrays, Web Services, Regexps, Math. | | | Contents Page - a script to build contents pages. Categories : Complete Programs, PHP, Utilities, Filesystem | | | GuestBook Light - a plug and play application for any website. Categories : PHP, Complete Programs, Filesystem, Sessions | |
| | | | igor petrov wrote :66
IMHO there is one mistake in 4-th line of the example
361.
for($i = sizeof($a1); $i >= 1; $i--)
should be like
for($i = sizeof($a1) - 1; $i >= 1; $i--)
| |
|
|