/php/pear/PHP/Compat/Function/array_change_key_case.php

https://gitlab.com/trang1104/portable_project · PHP · 64 lines · 25 code · 9 blank · 30 comment · 5 complexity · 02953d8f36ca8e1dcce99cb0bee16919 MD5 · raw file

  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. if (!defined('CASE_LOWER')) {
  21. define('CASE_LOWER', 0);
  22. }
  23. if (!defined('CASE_UPPER')) {
  24. define('CASE_UPPER', 1);
  25. }
  26. /**
  27. * Replace array_change_key_case()
  28. *
  29. * @category PHP
  30. * @package PHP_Compat
  31. * @link http://php.net/function.array_change_key_case
  32. * @author Stephan Schmidt <schst@php.net>
  33. * @author Aidan Lister <aidan@php.net>
  34. * @version $Revision: 1.11 $
  35. * @since PHP 4.2.0
  36. * @require PHP 4.0.0 (user_error)
  37. */
  38. if (!function_exists('array_change_key_case')) {
  39. function array_change_key_case($input, $case = CASE_LOWER)
  40. {
  41. if (!is_array($input)) {
  42. user_error('array_change_key_case(): The argument should be an array',
  43. E_USER_WARNING);
  44. return false;
  45. }
  46. $output = array ();
  47. $keys = array_keys($input);
  48. $casefunc = ($case == CASE_LOWER) ? 'strtolower' : 'strtoupper';
  49. foreach ($keys as $key) {
  50. $output[$casefunc($key)] = $input[$key];
  51. }
  52. return $output;
  53. }
  54. }
  55. ?>