mgd_sort_group_id_array()

This function supports the mgd_group_id_array() function and provides the core sorting functionality. It is independent from the grouping code to ease debugging and make resorting easier.

Calling Syntax

function mgd_sort_group_id_array(&$array,
                                 $element_type, $group_type,
                                 $elementsortkey = "unsorted", 
                                 $groupsortkey = "unsorted",
                                 $elementsorting = SORT_REGULAR,
                                 $groupsorting = SORT_REGULAR )

Synopsis

Basically this function does the sorting for mgd_group_id_array(). The only difference is that it receives the Array by-reference and sorts it in place. All other parameters worke like in mgd_group_id_array().

Dependencies

Code

<?php

function mgd_sort_group_id_array(&$array,
  
$element_type, $group_type,
  
$elementsortkey = "unsorted", $groupsortkey = "unsorted",
  
$elementsorting = SORT_REGULAR,
  
$groupsorting = SORT_REGULAR ) {
  
  
  
// Sort the groups
  
  
if ($groupsortkey != "unsorted")
  {
    
$found_keys = array();
      
    foreach (
$array as $key => $value)
      
$found_keys[] = $key;
    
    
mgd_sort_id_array($found_keys, $groupsortkey, $group_type,
      
$groupsorting);
    
    
$newresult = array();
    foreach (
$found_keys as $key)
      
$newresult[$key] = $array[$key];
    
    
$array = $newresult;
  }
  
  
// Now sort the subarrays
  
  
if ($elementsortkey != "unsorted")
  {
    foreach (
$array as $k => $elements)
      
mgd_sort_id_array($array[$k], $elementsortkey,
        
$element_type, $elementsorting);
  }

}

?>