/php/pear/PHP/Compat/Function/array_udiff_uassoc.php

https://gitlab.com/trang1104/portable_project · PHP · 82 lines · 42 code · 8 blank · 32 comment · 9 complexity · e1ffe99d89f1d402ea942d91650e9e16 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: Aidan Lister <aidan@php.net> |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: array_udiff_uassoc.php,v 1.8 2005/01/26 04:55:13 aidan Exp $
  19. /**
  20. * Replace array_udiff_uassoc()
  21. *
  22. * @category PHP
  23. * @package PHP_Compat
  24. * @link http://php.net/function.array_udiff_uassoc
  25. * @author Aidan Lister <aidan@php.net>
  26. * @version $Revision: 1.8 $
  27. * @since PHP 5
  28. * @require PHP 4.0.6 (is_callable)
  29. */
  30. if (!function_exists('array_udiff_uassoc')) {
  31. function array_udiff_uassoc()
  32. {
  33. $args = func_get_args();
  34. if (count($args) < 3) {
  35. user_error('Wrong parameter count for array_udiff_uassoc()', E_USER_WARNING);
  36. return;
  37. }
  38. // Get compare function
  39. $compare_func = array_pop($args);
  40. if (!is_callable($compare_func)) {
  41. if (is_array($compare_func)) {
  42. $compare_func = $compare_func[0] . '::' . $compare_func[1];
  43. }
  44. user_error('array_udiff_uassoc() Not a valid callback ' . $compare_func, E_USER_WARNING);
  45. return;
  46. }
  47. // Check arrays
  48. $count = count($args);
  49. for ($i = 0; $i < $count; $i++) {
  50. if (!is_array($args[$i])) {
  51. user_error('array_udiff_uassoc() Argument #' .
  52. ($i + 1) . ' is not an array', E_USER_WARNING);
  53. return;
  54. }
  55. }
  56. // Traverse values of the first array
  57. $diff = array ();
  58. foreach ($args[0] as $key => $value) {
  59. // Check all arrays
  60. for ($i = 1; $i < $count; $i++) {
  61. if (!array_key_exists($key, $args[$i])) {
  62. continue;
  63. }
  64. $result = call_user_func($compare_func, $value, $args[$i][$key]);
  65. if ($result === 0) {
  66. continue 2;
  67. }
  68. }
  69. $diff[$key] = $value;
  70. }
  71. return $diff;
  72. }
  73. }
  74. ?>