source: branches/version-2_5-dev/data/module/Compat/Compat/Function/array_change_key_case.php @ 19792

Revision 19792, 2.4 KB checked in by Seasoft, 13 years ago (diff)

#744(PHP4 互換用途ソースを将来的に切り捨てやすい仕組みづくり)

Line 
1<?php
2// +----------------------------------------------------------------------+
3// | PHP Version 4                                                        |
4// +----------------------------------------------------------------------+
5// | Copyright (c) 1997-2004 The PHP Group                                |
6// +----------------------------------------------------------------------+
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        |
9// | available at through the world-wide-web at                           |
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   |
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.               |
14// +----------------------------------------------------------------------+
15// | Authors: Stephan Schmidt <schst@php.net>                             |
16// |          Aidan Lister <aidan@php.net>                                |
17// +----------------------------------------------------------------------+
18//
19// $Id: array_change_key_case.php,v 1.11 2005/12/07 21:08:57 aidan Exp $
20
21
22if (!defined('CASE_LOWER')) {
23    define('CASE_LOWER', 0);
24}
25
26if (!defined('CASE_UPPER')) {
27    define('CASE_UPPER', 1);
28}
29
30
31/**
32 * Replace array_change_key_case()
33 *
34 * @category    PHP
35 * @package     PHP_Compat
36 * @link        http://php.net/function.array_change_key_case
37 * @author      Stephan Schmidt <schst@php.net>
38 * @author      Aidan Lister <aidan@php.net>
39 * @version     $Revision: 1.11 $
40 * @since       PHP 4.2.0
41 * @require     PHP 4.0.0 (user_error)
42 */
43if (!function_exists('array_change_key_case')) {
44    function array_change_key_case($input, $case = CASE_LOWER)
45    {
46        if (!is_array($input)) {
47            user_error('array_change_key_case(): The argument should be an array',
48                E_USER_WARNING);
49            return false;
50        }
51
52        $output   = array ();
53        $keys     = array_keys($input);
54        $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';
55
56        foreach ($keys as $key) {
57            $output[$casefunc($key)] = $input[$key];
58        }
59
60        return $output;
61    }
62}
63
64?>
Note: See TracBrowser for help on using the repository browser.