onetone_array_sort

The Onetone onetone array sort function.

Description

onetone_array_sort( $array, $keys, (string) $type = 'asc' ); 

Parameters (3)

0. $array
The array.
1. $keys
The keys.
2. $type — Optional. (string) => 'asc'
The type.

Usage

  1. if ( !function_exists( 'onetone_array_sort' ) ) { 
  2. require_once '/includes/theme-functions.php'; 
  3.  
  4. // The array. 
  5. $array = null; 
  6.  
  7. // The keys. 
  8. $keys = null; 
  9.  
  10. // The type. 
  11. $type = 'asc'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = onetone_array_sort($array, $keys, $type); 
  15.  

Defined (1)

The function is defined in the following location(s).

/includes/theme-functions.php  
  1. function onetone_array_sort($array, $keys, $type='asc') { 
  2.  
  3. if(!isset($array) || !is_array($array) || empty($array)) { 
  4. return ''; 
  5. if(!isset($keys) || trim($keys)=='') { 
  6. return ''; 
  7. if(!isset($type) || $type=='' || !in_array(strtolower($type), array('asc', 'desc'))) { 
  8. return ''; 
  9. $keysvalue=array(); 
  10. foreach($array as $key=>$val) { 
  11. $val[$keys] = str_replace('-', '', $val[$keys]); 
  12. $val[$keys] = str_replace(' ', '', $val[$keys]); 
  13. $val[$keys] = str_replace(':', '', $val[$keys]); 
  14. $keysvalue[] =$val[$keys]; 
  15. asort($keysvalue);  
  16. reset($keysvalue);  
  17. foreach($keysvalue as $key=>$vals) { 
  18. $keysort[] = $key; 
  19. $keysvalue = array(); 
  20. $count=count($keysort); 
  21. if(strtolower($type) != 'asc') { 
  22. for($i=$count-1; $i>=0; $i--) { 
  23. $keysvalue[] = $array[$keysort[$i]]; 
  24. }else{ 
  25. for($i=0; $i<$count; $i++) { 
  26. if(isset($array[$keysort[$i]])) 
  27. $keysvalue[] = $array[$keysort[$i]]; 
  28. return $keysvalue;