daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest May 19th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static function sort_months($base_directory) {
  2.         $month_year_array = array();
  3.         $old_year = "";
  4.         $years_array =array();
  5.         $sorted_array = array();
  6.        
  7.         for($index = 0; $index < count($base_directory); $index++) {
  8.             // april_2009
  9.             $current_directory = $base_directory[$index];
  10.             // ("2009" => "april")
  11.             $complete_month_of_year_array = array();
  12.             // 2009
  13.             $new_year = substr($current_directory, strpos($current_directory, "_") + 1);
  14.            
  15.             if ($old_year != $new_year) {
  16.                 // "april"
  17.                 $month_array = array();
  18.                
  19.                 foreach ($base_directory as $directory) {
  20.                     if(substr($directory, strpos($directory, "_") + 1) == $new_year) {
  21.                         array_push($month_array, $directory);
  22.                     }
  23.                 }
  24.  
  25.                 if (count($month_array) > 0) {
  26.                     $complete_month_of_year_array = array($new_year => $month_array);
  27.                     array_push($month_year_array, array($new_year => $month_array));
  28.                     array_push($years_array, $new_year);
  29.                 }
  30.             }
  31.            
  32.             $old_year = $new_year;
  33.         }
  34.  
  35.         sort($years_array);
  36.         print_r($month_year_array);
  37.        
  38.         foreach ($years_array as $year) {
  39.             $current =  $month_year_array[$year];
  40.             foreach ($current as $d) {
  41.                 array_push($sorted_array, $d);
  42.             }
  43.         }
  44.  
  45.         print_r($sorted_array);
  46.     }
  47.  
  48. output
  49.  
  50. Array ( [0] => Array ( [2010] => Array ( [0] => april_2010 [1] => march_2010 ) ) [1] => Array ( [2009] => Array ( [0] => januari_2009 [1] => april_2009 ) ) )
  51.  
  52. prefered Array ( [2010] => Array ( [0] => april_2010 [1] => march_2010 )  [2009] => Array ( [0] => januari_2009 [1] => april_2009 )  )
RAW Paste Data
Top