/php/pear/PHP/Compat/Function/array_diff_assoc.php

https://gitlab.com/trang1104/portable_project · PHP · 76 lines · 34 code · 8 blank · 34 comment · 6 complexity · fcb170979f96d68bc3aa71c148ea2868 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_diff_assoc.php,v 1.12 2005/12/07 21:08:57 aidan Exp $
  19. /**
  20. * Replace array_diff_assoc()
  21. *
  22. * @category PHP
  23. * @package PHP_Compat
  24. * @link http://php.net/function.array_diff_assoc
  25. * @author Aidan Lister <aidan@php.net>
  26. * @version $Revision: 1.12 $
  27. * @since PHP 4.3.0
  28. * @require PHP 4.0.0 (user_error)
  29. */
  30. if (!function_exists('array_diff_assoc')) {
  31. function array_diff_assoc()
  32. {
  33. // Check we have enough arguments
  34. $args = func_get_args();
  35. $count = count($args);
  36. if (count($args) < 2) {
  37. user_error('Wrong parameter count for array_diff_assoc()', E_USER_WARNING);
  38. return;
  39. }
  40. // Check arrays
  41. for ($i = 0; $i < $count; $i++) {
  42. if (!is_array($args[$i])) {
  43. user_error('array_diff_assoc() Argument #' .
  44. ($i + 1) . ' is not an array', E_USER_WARNING);
  45. return;
  46. }
  47. }
  48. // Get the comparison array
  49. $array_comp = array_shift($args);
  50. --$count;
  51. // Traverse values of the first array
  52. foreach ($array_comp as $key => $value) {
  53. // Loop through the other arrays
  54. for ($i = 0; $i < $count; $i++) {
  55. // Loop through this arrays key/value pairs and compare
  56. foreach ($args[$i] as $comp_key => $comp_value) {
  57. if ((string)$key === (string)$comp_key &&
  58. (string)$value === (string)$comp_value)
  59. {
  60. unset($array_comp[$key]);
  61. }
  62. }
  63. }
  64. }
  65. return $array_comp;
  66. }
  67. }
  68. ?>