Return to Snippet

Revision: 32783
at October 2, 2010 05:11 by lluisr


Initial Code
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('swapValues2')) {
	function swapValues2( $array, $dex, $dex2 ) {
		list($array[$dex],$array[$dex2]) = array($array[$dex2], $array[$dex]);
		return $array;
	}
}

if ( ! function_exists('bubbleSort')) {
	function bubbleSort( $array)
	{
		for( $out=0, $size = count($array);$out < $size -1 ;$out++ )
   	    {
 			for( $in = $out + 1;$in < $size;$in++)
   	        {
			      if (strtotime($array[ $out ]) > strtotime($array[ $in ]))
   	              {
				  	$array = swapValues2($array, $out, $in);
   	              }
   			}
  		}
		return $array;
	}
}


/* End of file my_bubblesort_helper.php */
/* Location: ./system/application/helpers/my_bubblesort_helper.php */

Initial URL


Initial Description
searching for a date sort function I found:  http://slevy1.wordpress.com/2010/06/30/sorting-date-strings-in-php/ and built my codeigniter helper

call : $arrSortedDates = bubbleSort( $unsorted ); (previous->helper autoload)

Initial Title
codeigniter bubblesort helper

Initial Tags
php, sort, array, codeigniter

Initial Language
PHP