Line 1... |
Line 1... |
1 |
<?php |
1 |
<?php |
2 |
// +----------------------------------------------------------------------+ |
2 |
// +----------------------------------------------------------------------+ |
3 |
// | PHP Version 4 | |
3 |
// | PHP Version 4 | |
4 |
// +----------------------------------------------------------------------+ |
4 |
// +----------------------------------------------------------------------+ |
5 |
// | Copyright (c) 1997-2004 The PHP Group | |
5 |
// | Copyright (c) 1997-2004 The PHP Group | |
6 |
// +----------------------------------------------------------------------+ |
6 |
// +----------------------------------------------------------------------+ |
7 |
// | This source file is subject to version 3.0 of the PHP license, | |
7 |
// | This source file is subject to version 3.0 of the PHP license, | |
8 |
// | that is bundled with this package in the file LICENSE, and is | |
8 |
// | that is bundled with this package in the file LICENSE, and is | |
9 |
// | available at through the world-wide-web at | |
9 |
// | available at through the world-wide-web at | |
10 |
// | http://www.php.net/license/3_0.txt. | |
10 |
// | http://www.php.net/license/3_0.txt. | |
11 |
// | If you did not receive a copy of the PHP license and are unable to | |
11 |
// | If you did not receive a copy of the PHP license and are unable to | |
12 |
// | obtain it through the world-wide-web, please send a note to | |
12 |
// | obtain it through the world-wide-web, please send a note to | |
13 |
// | license@php.net so we can mail you a copy immediately. | |
13 |
// | license@php.net so we can mail you a copy immediately. | |
14 |
// +----------------------------------------------------------------------+ |
14 |
// +----------------------------------------------------------------------+ |
15 |
// | Authors: Stephan Schmidt <schst@php.net> | |
15 |
// | Authors: Stephan Schmidt <schst@php.net> | |
16 |
// | Aidan Lister <aidan@php.net> | |
16 |
// | Aidan Lister <aidan@php.net> | |
17 |
// +----------------------------------------------------------------------+ |
17 |
// +----------------------------------------------------------------------+ |
18 |
// |
18 |
// |
19 |
// $Id: array_change_key_case.php,v 1.11 2005/12/07 21:08:57 aidan Exp $ |
19 |
// $Id: array_change_key_case.php,v 1.11 2005/12/07 21:08:57 aidan Exp $ |
20 |
|
20 |
|
21 |
|
21 |
|
22 |
if (!defined('CASE_LOWER')) { |
22 |
if (!defined('CASE_LOWER')) { |
23 |
define('CASE_LOWER', 0); |
23 |
define('CASE_LOWER', 0); |
24 |
} |
24 |
} |
25 |
|
25 |
|
26 |
if (!defined('CASE_UPPER')) { |
26 |
if (!defined('CASE_UPPER')) { |
27 |
define('CASE_UPPER', 1); |
27 |
define('CASE_UPPER', 1); |
28 |
} |
28 |
} |
29 |
|
29 |
|
30 |
|
30 |
|
31 |
/** |
31 |
/** |
32 |
* Replace array_change_key_case() |
32 |
* Replace array_change_key_case() |
33 |
* |
33 |
* |
34 |
* @category PHP |
34 |
* @category PHP |
35 |
* @package PHP_Compat |
35 |
* @package PHP_Compat |
36 |
* @link http://php.net/function.array_change_key_case |
36 |
* @link http://php.net/function.array_change_key_case |
37 |
* @author Stephan Schmidt <schst@php.net> |
37 |
* @author Stephan Schmidt <schst@php.net> |
38 |
* @author Aidan Lister <aidan@php.net> |
38 |
* @author Aidan Lister <aidan@php.net> |
39 |
* @version $Revision: 1.11 $ |
39 |
* @version $Revision: 1.11 $ |
40 |
* @since PHP 4.2.0 |
40 |
* @since PHP 4.2.0 |
41 |
* @require PHP 4.0.0 (user_error) |
41 |
* @require PHP 4.0.0 (user_error) |
42 |
*/ |
42 |
*/ |
43 |
if (!function_exists('array_change_key_case')) { |
43 |
if (!function_exists('array_change_key_case')) { |
44 |
function array_change_key_case($input, $case = CASE_LOWER) |
44 |
function array_change_key_case($input, $case = CASE_LOWER) |
45 |
{ |
45 |
{ |
46 |
if (!is_array($input)) { |
46 |
if (!is_array($input)) { |
47 |
user_error('array_change_key_case(): The argument should be an array', |
47 |
user_error('array_change_key_case(): The argument should be an array', |
48 |
E_USER_WARNING); |
48 |
E_USER_WARNING); |
49 |
return false; |
49 |
return false; |
50 |
} |
50 |
} |
51 |
|
51 |
|
52 |
$output = array (); |
52 |
$output = array (); |
53 |
$keys = array_keys($input); |
53 |
$keys = array_keys($input); |
54 |
$casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper'; |
54 |
$casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper'; |
55 |
|
55 |
|
56 |
foreach ($keys as $key) { |
56 |
foreach ($keys as $key) { |
57 |
$output[$casefunc($key)] = $input[$key]; |
57 |
$output[$casefunc($key)] = $input[$key]; |
58 |
} |
58 |
} |
59 |
|
59 |
|
60 |
return $output; |
60 |
return $output; |
61 |
} |
61 |
} |
62 |
} |
62 |
} |
63 |
|
63 |
|
64 |
?> |
64 |
?> |
65 |
|
65 |
|