酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Arr.php 1.1 KiB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2015 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace think\helper;
  12. class Arr
  13. {
  14. public static function isAssoc(array $array)
  15. {
  16. $keys = array_keys($array);
  17. return array_keys($keys) !== $keys;
  18. }
  19. public static function sortRecursive($array)
  20. {
  21. foreach ($array as &$value) {
  22. if (is_array($value)) {
  23. $value = static::sortRecursive($value);
  24. }
  25. }
  26. if (static::isAssoc($array)) {
  27. ksort($array);
  28. } else {
  29. sort($array);
  30. }
  31. return $array;
  32. }
  33. }