DictionaryUtil.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\utils\Ocr\Util;
  8. /*
  9. * Licensed to the Apache Software Foundation (ASF) under one
  10. * or more contributor license agreements. See the NOTICE file
  11. * distributed with this work for additional information
  12. * regarding copyright ownership. The ASF licenses this file
  13. * to you under the Apache License, Version 2.0 (the
  14. * "License"); you may not use this file except in compliance
  15. * with the License. You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing,
  20. * software distributed under the License is distributed on an
  21. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  22. * KIND, either express or implied. See the License for the
  23. * specific language governing permissions and limitations
  24. * under the License.
  25. */
  26. /**
  27. * 集合对象的元素处理
  28. */
  29. class DictionaryUtil
  30. {
  31. public static function Add($dic, $key, $value) {
  32. if (null == $value) {
  33. return;
  34. }
  35. if (null == $dic)
  36. {
  37. $dic = Array();
  38. }
  39. foreach($dic as $itemKey=>$itemValue)
  40. {
  41. //区分大小写
  42. if ($itemKey == $key) {
  43. $dic[$key] = $itemValue;
  44. return;
  45. }
  46. }
  47. $dic[$key] = $value;
  48. }
  49. public static function Get($dic, $key)
  50. {
  51. if (array_key_exists($key, $dic)) {
  52. return $dic[$key];
  53. }
  54. return null;
  55. }
  56. public static function Pop(&$dic, $key)
  57. {
  58. $value = null;
  59. if (array_key_exists($key, $dic)) {
  60. $value = $dic[$key];
  61. unset($dic[$key]);
  62. }
  63. return $value;
  64. }
  65. }