source: trunk/phpgwapi/inc/class.arrayfunctions.inc.php @ 2

Revision 2, 2.3 KB checked in by niltonneto, 17 years ago (diff)

Removida todas as tags usadas pelo CVS ($Id, $Source).
Primeira versão no CVS externo.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /*******************************************************************\
3        * phpGroupWare API - Arrayfunctions                                 *
4        * Written by Lars Kneschke <lkneschke@phpgw.de>                     *
5        * Copyright (C) 2002, 2003 Lars Kneschke                            *
6        * ----------------------------------------------------------------- *
7        * This library is part of the phpGroupWare API                      *
8        * ----------------------------------------------------------------- *
9        * This program is free software; you can redistribute it and/or     *
10        * modify it under the terms of the GNU General Public License as    *
11        * published by the Free Software Foundation; either version 2 of    *
12        * the License, or (at your option) any later version.               *
13        *                                                                   *
14        * This program is distributed in the hope that it will be useful,   *
15        * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
16        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  *
17        * General Public License for more details.                          *
18        *                                                                   *
19        * You should have received a copy of the GNU General Public License *
20        * along with this program; if not, write to the Free Software       *
21        * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         *
22        \*******************************************************************/
23
24        class arrayfunctions
25        {
26                function arrayfunctions($vars='')
27                {
28                }
29
30                /*
31                * arfsort() - (AR)ray (F)ield Sort.
32                * Sort a multi-dimensional array according
33                * to a list of fields.
34                * @param $a The array to sort
35                * @param $fl Field list (in order of importance)
36                */
37               
38                function arfsort( $a, $fl, $_sort='ASC' )
39                {
40                        $GLOBALS['__ARFSORT_LIST__'] = $fl;
41                       
42                        $this->sort=$_sort;
43
44                        if (is_array($a))
45                        {
46                                usort( $a, array($this,'arfsort_func') );
47                                return $a;
48                        }
49                        return False;
50                }
51
52                /*
53                * Internal sorting function for arfsort()
54                */
55                function arfsort_func( $a, $b )
56                {
57                        foreach( $GLOBALS['__ARFSORT_LIST__'] as $f )
58                        {
59                                if($this->sort == 'ASC')
60                                {
61                                        $strc = strcmp( $a[$f], $b[$f] );
62                                }
63                                else
64                                {
65                                        $strc = strcmp( $b[$f], $a[$f] );
66                                }
67                                if ( $strc != 0 )
68                                {
69                                        return $strc;
70                                }
71                        }
72                        return 0;
73                }
74
75        } // end class arrayfunctions
76?>
Note: See TracBrowser for help on using the repository browser.