PHP Bubble Sort

One of an occasional series of posts on PHP algorithms. I found this originally at United Scripters, and bookmarked it for some reason.


function bubbleSort($array=array()/*could have been a pointer*/){
for($j=($startIndex)?$startIndex:1; $j<=$lastIndex; $j++){
if( $array[$j-1] > $array[$j] ){/*SWAP:*/
if($newStartIndex===false){return $array;};
/* keep this comment to reuse freely:
Orwant, Hietaniemi, Macdonald algorithm as Php implemented by: */

Leave a Comment

To prove you're a person (not a spam script), type the answer to the math equation shown in the picture. Click on the picture to hear an audio file of the equation.
Click to hear an audio file of the anti-spam equation