1   <?php
  2   /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3   // +----------------------------------------------------------------------+
  4   // | PHP Version 4                                                        |
  5   // +----------------------------------------------------------------------+
  6   // | Copyright (c) 1997-2004 The PHP Group                                |
  7   // +----------------------------------------------------------------------+
  8   // | This source file is subject to version 3.0 of the PHP license,       |
  9   // | that is bundled with this package in the file LICENSE, and is        |
  10   // | available at through the world-wide-web at                           |
  11   // | http://www.php.net/license/3_0.txt.                                  |
  12   // | If you did not receive a copy of the PHP license and are unable to   |
  13   // | obtain it through the world-wide-web, please send a note to          |
  14   // | license@php.net so we can mail you a copy immediately.               |
  15   // +----------------------------------------------------------------------+
  16   // | Authors: Stephan Schmidt <schst@php.net>                             |
  17   // |          Aidan Lister <aidan@php.net>                                |
  18   // +----------------------------------------------------------------------+
  19   //
  20   // $Id: array_udiff.php,v 1.1 2004-10-26 18:22:16 kostja Exp $
  21   //
  22  
  23  
  24   /**
  25    * Replace array_udiff()
  26    *
  27    * @category    PHP
  28    * @package     PHP_Compat
  29    * @link        http://php.net/function.array_udiff
  30    * @author      Stephan Schmidt <schst@php.net>
  31    * @author      Aidan Lister <aidan@php.net>
  32    * @version     $Revision: 1.1 $
  33    * @since       PHP 5
  34    * @require     PHP 4.0.1 (trigger_error)
  35    */
  36   if (!function_exists('array_udiff'))
  37   {
  38       function array_udiff ()
  39       {
  40           $args = func_get_args();
  41  
  42           if (count($args) < 3) {
  43               trigger_error('Wrong parameter count for array_udiff()', E_USER_WARNING);
  44               return null;
  45           }
  46      
  47           // Get compare function
  48           $compare_func = array_pop($args);
  49           if (!is_callable($compare_func)) {
  50               if (is_array($compare_func)) {
  51                   $compare_func = $compare_func[0] . '::' . $compare_func[1];
  52               }
  53               trigger_error('array_udiff() Not a valid callback ' . $compare_func, E_USER_WARNING);
  54               return null;
  55           }
  56      
  57           // Check arrays
  58           $cnt = count($args);
  59           for ($i = 0; $i < $cnt; $i++) {
  60               if (!is_array($args[$i])) {
  61                   trigger_error('array_udiff() Argument #' . ($i + 1). ' is not an array', E_USER_WARNING);
  62                   return null;
  63               }
  64           }
  65      
  66           $diff = array ();
  67           // Traverse values of the first array
  68           foreach ($args[0] as $key => $value) {
  69               // Check all arrays
  70               for ($i = 1; $i < $cnt; $i++) {
  71                   foreach ($args[$i] as $cmp_value) {
  72                       $result = call_user_func($compare_func, $value, $cmp_value);
  73                       if ($result === 0) {
  74                           continue 3;
  75                       }
  76                   }
  77               }
  78               $diff[$key] = $value;
  79           }
  80           return $diff;
  81       }
  82   }
  83  
  84   ?>