Simple bubble sort on PHP

“Bubble Sort” is a classic sort. It used ~76% of programmers.
Example ↓

function bubbleSort ($data_array = array() ) {
$result_array = $data_array;
$size = sizeof($result_array);
if ($size)
  for( $i = 0 ; $i < $size; $i++) {      
    for( $j = $size-1; $j > $i; $j-- ) { 
      if ( $result_array[$j-1] > $result_array[$j] ) {
            $buf = $result_array[$j-1]; 
            $result_array[$j-1] = $result_array[$j]; 
            $result_array[$j] = $buf;
		}
	}
  }
return $result_array;
}
 
$test_array = array(1, 9, 5, 2, 4, 5, 7, 0, 3, 8, 6); 
$result = bubbleSort ($test_array);
echo '<pre>'; print_R($result); echo '</pre>';

Results ↓
Continue reading Simple bubble sort on PHP