Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Function for sorting time by converting each time type (Seconds, Hours, Days, Weeks, Months, Years) to Hours
- * Then stores the original value in a new temp array as a key, and the hour value as the actual value.
- * Next calls the asort() function to sort it low->high, clears the original array, and updates it with the sorted info.
- */
- function SortTime($a){
- $a_temp = [];
- $second = '/\d+\s+second(\s|s|)/i';
- $hour = '/\d+\s+hour(\s|s|)/i';
- $day = '/\d+\s+day(\s|s|)/i';
- $week = '/\d+\s+week(\s|s|)/i';
- $month = '/\d+\s+month(\s|s|)/i';
- $year = '/\d+\s+year(\s|s|)/i';
- $digit = '/\d+/i';
- foreach($a as $a_item){
- $valueTotal = 0;
- if(preg_match($year, $a_item,$yearARR)){
- preg_match($digit,$yearARR[0],$yearNum);
- $valueTotal += ($yearNum[0]*365*24);
- }
- if(preg_match($month, $a_item,$monthARR)){
- preg_match($digit,$monthARR[0],$monthNum);
- $valueTotal += ($monthNum[0]*30*24);
- }
- if(preg_match($week, $a_item,$weekARR)){
- preg_match($digit,$weekARR[0],$weekNum);
- $valueTotal += ($weekNum[0]*7*24);
- }
- if(preg_match($day, $a_item,$dayARR)){
- preg_match($digit,$dayARR[0],$dayNum);
- $valueTotal += ($dayNum[0]*24);
- }
- if(preg_match($hour, $a_item,$hourARR)){
- preg_match($digit,$hourARR[0],$hourNum);
- $valueTotal += $hourNum[0];
- }
- if(preg_match($second, $a_item,$secondARR)){
- preg_match($digit,$secondARR[0],$secondNum);
- $valueTotal += ($secondNum[0]/60/60);
- }
- $a_temp[$a_item] = $valueTotal;
- }
- asort($a_temp);
- $a=[];
- return($a_temp);
- }
Advertisement
Add Comment
Please, Sign In to add comment