Bubble Sort
Bubble sort (a.k.a Sinking Sort and Comparison Sort) is a sorting algorithm that works by repeatedly swapping and adjacent elements if they are in wrong order.
function BubbleSort(&$data, $count) {
for ($i = 1; $i < $count; $i++)
{
for ($j = 0; $j < $count - $i; $j++)
{
if ($data[$j] > $data[$j + 1])
{
$data[$j] ^= $data[$j + 1];
$data[$j + 1] ^= $data[$j];
$data[$j] ^= $data[$j + 1];
}
}
}
}
Example
$data = array(-1, 25, -58964, 8547, -119, 0, 78596);
BubbleSort($data, 7);
Output
-58964
-119
-1
0
25
8547
78596