How to speed up the processing of dates
-
function pc_date_sort() the example shows how to sort the dates.
function pc_date_sort($a, $b) { list($a_month, $a_day, $a_year) = explode('/', $a); list($b_month, $b_day, $b_year) = explode('/', $b); if ($a_year > $b_year ) return 1; if ($a_year < $b_year ) return -1; if ($a_month > $b_month) return 1; if ($a_month < $b_month) return -1; if ($a_day > $b_day ) return 1; if ($a_day < $b_day ) return -1; return 0; } $dates = array('12/14/2000', '08/07/1999', '08/10/2001'); usort($dates, 'pc_date_sort'); echo '<pre>'; print_r($dates);
Weort(s) is often the function of usort whenever it is I need to compare the two elements recalculate the values, return. The sorting function, which slows the process.
Please help me streamline the code. How to avoid unnecessary work?
-
use standard built-in http://php.net/manual/en/class.datetime.php ♪ It used to be a bicycle town with dates.
- a built-in datetime written on C, it will be faster,
- He's challenged and safer.
- He offers more opportunities than his bike.
You can add it to your class/function, inheriting it.
http://php.net/manual/en/datetime.createfromformat.php Create objects from your format of dates without any additional predatory and hand-operated lines