Overview

Packages

  • Util

Classes

  • Horde_Array
  • Horde_Array_Sort_Helper
  • Horde_Domhtml
  • Horde_String
  • Horde_Util
  • Horde_Variables
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Helper class for sorting arrays on arbitrary criteria for usort/uasort.
 4:  *
 5:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
 6:  *
 7:  * See the enclosed file COPYING for license information (LGPL). If you
 8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 9:  *
10:  * @author   Marko Djukic <marko@oblo.com>
11:  * @author   Jan Schneider <jan@horde.org>
12:  * @author   Michael Slusarz <slusarz@horde.org>
13:  * @category Horde
14:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
15:  * @package  Util
16:  */
17: class Horde_Array_Sort_Helper
18: {
19:     /**
20:      * The array key to sort by.
21:      *
22:      * @var string
23:      */
24:     public $key;
25: 
26:     /**
27:      * Compare two associative arrays by the array key defined in self::$key.
28:      *
29:      * @param array $a
30:      * @param array $b
31:      */
32:     public function compare($a, $b)
33:     {
34:         return strcoll(Horde_String::lower($a[$this->key], true, 'UTF-8'), Horde_String::lower($b[$this->key], true, 'UTF-8'));
35:     }
36: 
37:     /**
38:      * Compare, in reverse order, two associative arrays by the array key
39:      * defined in self::$key.
40:      *
41:      * @param scalar $a  TODO
42:      * @param scalar $b  TODO
43:      *
44:      * @return TODO
45:      */
46:     public function reverseCompare($a, $b)
47:     {
48:         return strcoll(Horde_String::lower($b[$this->key], true, 'UTF-8'), Horde_String::lower($a[$this->key], true, 'UTF-8'));
49:     }
50: 
51:     /**
52:      * Compare array keys case insensitively for uksort.
53:      *
54:      * @param scalar $a  TODO
55:      * @param scalar $b  TODO
56:      *
57:      * @return TODO
58:      */
59:     public function compareKeys($a, $b)
60:     {
61:         return strcoll(Horde_String::lower($a, true, 'UTF-8'), Horde_String::lower($b, true, 'UTF-8'));
62:     }
63: 
64:     /**
65:      * Compare, in reverse order, array keys case insensitively for uksort.
66:      *
67:      * @param scalar $a  TODO
68:      * @param scalar $b  TODO
69:      *
70:      * @return TODO
71:      */
72:     public function reverseCompareKeys($a, $b)
73:     {
74:         return strcoll(Horde_String::lower($b, true, 'UTF-8'), Horde_String::lower($a, true, 'UTF-8'));
75:     }
76: 
77: }
78: 
API documentation generated by ApiGen