cvs: pear /PHP_Compat/Compat/Function array_udiff_assoc.php array_udiff_uassoc.php array_uintersect.php array_uintersect_assoc.php
array_uintersect_uassoc.php

From: Date: Tue, 31 Aug 2004 10:46:05 +0000
Subject: cvs: pear /PHP_Compat/Compat/Function array_udiff_assoc.php array_udiff_uassoc.php array_uintersect.php array_uintersect_assoc.php
array_uintersect_uassoc.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-23522@lists.php.net to get a copy of this message
aidan Tue Aug 31 06:46:05 2004 EDT Modified files: /pear/PHP_Compat/Compat/Function array_udiff_assoc.php array_udiff_uassoc.php array_uintersect.php array_uintersect_assoc.php array_uintersect_uassoc.php Log: Fixed

http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/array_udiff_assoc.php?r1=1.9&r2=1.10&ty=u Index: pear/PHP_Compat/Compat/Function/array_udiff_assoc.php diff -u pear/PHP_Compat/Compat/Function/array_udiff_assoc.php:1.9 pear/PHP_Compat/Compat/Function/array_udiff_assoc.php:1.10 --- pear/PHP_Compat/Compat/Function/array_udiff_assoc.php:1.9 Tue Aug 31 06:35:27 2004 +++ pear/PHP_Compat/Compat/Function/array_udiff_assoc.php Tue Aug 31 06:46:05 2004 @@ -16,7 +16,7 @@ // | Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: array_udiff_assoc.php,v 1.9 2004/08/31 10:35:27 aidan Exp $ +// $Id: array_udiff_assoc.php,v 1.10 2004/08/31 10:46:05 aidan Exp $ /** @@ -26,7 +26,7 @@ * @package PHP_Compat * @author Stephan Schmidt <schst@php.net> * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.9 $ + * @version $Revision: 1.10 $ * @link http://php.net/function.array-udiff-assoc * @since PHP 5 * @require PHP 4.0.1 (trigger_error) @@ -43,10 +43,9 @@ // Get compare function $compare_func = array_pop($args); - if (!is_callable($compare_func)) - { + if (!is_callable($compare_func)) { if (is_array($compare_func)) { - $compare_func = $compare_func[0].'::'.$compare_func[1]; + $compare_func = $compare_func[0] . '::' . $compare_func[1]; } trigger_error('array_udiff_assoc() Not a valid callback ' . $compare_func, E_USER_WARNING); return; http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/array_udiff_uassoc.php?r1=1.2&r2=1.3&ty=u Index: pear/PHP_Compat/Compat/Function/array_udiff_uassoc.php diff -u pear/PHP_Compat/Compat/Function/array_udiff_uassoc.php:1.2 pear/PHP_Compat/Compat/Function/array_udiff_uassoc.php:1.3 --- pear/PHP_Compat/Compat/Function/array_udiff_uassoc.php:1.2 Sat Aug 28 05:14:07 2004 +++ pear/PHP_Compat/Compat/Function/array_udiff_uassoc.php Tue Aug 31 06:46:05 2004 @@ -15,7 +15,7 @@ // | Authors: Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: array_udiff_uassoc.php,v 1.2 2004/08/28 09:14:07 aidan Exp $ +// $Id: array_udiff_uassoc.php,v 1.3 2004/08/31 10:46:05 aidan Exp $ /** @@ -25,7 +25,7 @@ * @package PHP_Compat * @link http://php.net/function.array_udiff_uassoc * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.2 $ + * @version $Revision: 1.3 $ * @since PHP 5 * @require PHP 4.0.1 (trigger_error) */ @@ -33,7 +33,52 @@ { function array_udiff_uassoc() { + $args = func_get_args(); + if (count($args) < 3) { + trigger_error('Wrong parameter count for array_udiff_uassoc()', E_USER_WARNING); + return; + } + // Get compare function + $compare_func = array_pop($args); + if (!is_callable($compare_func)) { + if (is_array($compare_func)) { + $compare_func = $compare_func[0].'::'.$compare_func[1]; + } + trigger_error('array_udiff_uassoc() Not a valid callback ' . $compare_func, E_USER_WARNING); + return; + } + + // Check arrays + $count = count($args); + for ($i = 0; $i < $count; $i++) + { + if (!is_array($args[$i])) { + trigger_error('array_udiff_uassoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); + return; + } + } + + $diff = array (); + // Traverse values of the first array + foreach ($args[0] as $key => $value) + { + // Check all arrays + for ($i = 1; $i < $count; $i++) + { + if (!isset($args[$i][$key])) { + continue; + } + $result = call_user_func($compare_func, $value, $args[$i][$key]); + if ($result === 0) { + continue 2; + } + } + + $diff[$key] = $value; + } + + return $diff; } } http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/array_uintersect.php?r1=1.3&r2=1.4&ty=u Index: pear/PHP_Compat/Compat/Function/array_uintersect.php diff -u pear/PHP_Compat/Compat/Function/array_uintersect.php:1.3 pear/PHP_Compat/Compat/Function/array_uintersect.php:1.4 --- pear/PHP_Compat/Compat/Function/array_uintersect.php:1.3 Sat Aug 28 05:14:07 2004 +++ pear/PHP_Compat/Compat/Function/array_uintersect.php Tue Aug 31 06:46:05 2004 @@ -16,7 +16,7 @@ // | Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: array_uintersect.php,v 1.3 2004/08/28 09:14:07 aidan Exp $ +// $Id: array_uintersect.php,v 1.4 2004/08/31 10:46:05 aidan Exp $ /** @@ -27,7 +27,7 @@ * @link http://php.net/function.array_uintersect * @author Tom Buskens <ortega@php.net> * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.3 $ + * @version $Revision: 1.4 $ * @since PHP 5 * @require PHP 4.0.1 (trigger_error) */ @@ -35,53 +35,40 @@ { function array_uintersect() { - // Get arguments $args = func_get_args(); - if (count($args) < 3) { trigger_error('wrong parameter count for array_uintersect()', E_USER_WARNING); return; } - // Get callback functions - $user_func_item = array_pop($args); - - if (is_array($user_func_item) && count($user_func_item) === 2) { - $user_func_item = current($user_func_item) . '::' . current($user_func_item); - } - if (!is_callable($user_func_item)) { - trigger_error('array_uintersect() Not a valid callback ' . $user_func_item, E_USER_WARNING); + // Get compare function + $compare_func = array_pop($args); + if (!is_callable($compare_func)) { + if (is_array($compare_func)) { + $compare_func = $compare_func[0].'::'.$compare_func[1]; + } + trigger_error('array_uintersect() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); - for ($i = 0; $i !== $array_count; $i++) { - if (!is_array($args[$i])) { - trigger_error('array_uintersect() [...]: Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); + trigger_error('array_uintersect() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } - } // Compare entries $output = array(); foreach ($args[0] as $key => $item) { - for ($i = 1; $i !== $array_count; $i++) { - $array = $args[$i]; - foreach($array as $key0 => $item0) { - - if (!call_user_func($user_func_item, $item, $item0)) { - + if (!call_user_func($compare_func, $item, $item0)) { $output[$key] = $item; - } - } } } http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/array_uintersect_assoc.php?r1=1.4&r2=1.5&ty=u Index: pear/PHP_Compat/Compat/Function/array_uintersect_assoc.php diff -u pear/PHP_Compat/Compat/Function/array_uintersect_assoc.php:1.4 pear/PHP_Compat/Compat/Function/array_uintersect_assoc.php:1.5 --- pear/PHP_Compat/Compat/Function/array_uintersect_assoc.php:1.4 Sat Aug 28 05:14:07 2004 +++ pear/PHP_Compat/Compat/Function/array_uintersect_assoc.php Tue Aug 31 06:46:05 2004 @@ -16,7 +16,7 @@ // | Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: array_uintersect_assoc.php,v 1.4 2004/08/28 09:14:07 aidan Exp $ +// $Id: array_uintersect_assoc.php,v 1.5 2004/08/31 10:46:05 aidan Exp $ /** @@ -27,7 +27,7 @@ * @link http://php.net/function.array_uintersect_assoc * @author Tom Buskens <ortega@php.net> * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @since PHP 5 * @require PHP 4.0.1 (trigger_error) */ @@ -35,43 +35,35 @@ { function array_uintersect_assoc() { - // Get arguments $args = func_get_args(); - if (count($args) < 3) { trigger_error('wrong parameter count for array_uintersect_assoc()', E_USER_WARNING); return; } - // Get callback function + // Get compare function $user_func = array_pop($args); - - if (is_array($user_func) && count($user_func) === 2) { - $user_func = current($user_func) . '::' . current($user_func); - } if (!is_callable($user_func)) { + if (is_array($user_func)) { + $user_func = $user_func[0] . '::' . $user_func[1]; + } trigger_error('array_uintersect_assoc() Not a valid callback ' . $user_func, E_USER_WARNING); return; } // Check arrays $array_count = count($args); - for ($i = 0; $i !== $array_count; $i++) { - if (!is_array($args[$i])) { - trigger_error('array_uintersect_assoc() [...]: Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); + trigger_error('array_uintersect_assoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } - } // Compare entries $output = array(); foreach ($args[0] as $key => $item) { - for ($i = 1; $i !== $array_count; $i++) { - if (array_key_exists($key, $args[$i])) { $compare = call_user_func($user_func, $item, $args[$i][$key]); if ($compare === 0) { @@ -80,7 +72,6 @@ } } - } return $output; http://cvs.php.net/diff.php/pear/PHP_Compat/Compat/Function/array_uintersect_uassoc.php?r1=1.4&r2=1.5&ty=u Index: pear/PHP_Compat/Compat/Function/array_uintersect_uassoc.php diff -u pear/PHP_Compat/Compat/Function/array_uintersect_uassoc.php:1.4 pear/PHP_Compat/Compat/Function/array_uintersect_uassoc.php:1.5 --- pear/PHP_Compat/Compat/Function/array_uintersect_uassoc.php:1.4 Sat Aug 28 05:14:07 2004 +++ pear/PHP_Compat/Compat/Function/array_uintersect_uassoc.php Tue Aug 31 06:46:05 2004 @@ -12,11 +12,10 @@ // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ -// | Authors: Tom Buskens <ortega@php.net> | -// | Aidan Lister <aidan@php.net> | +// | Authors: Aidan Lister <aidan@php.net> | // +----------------------------------------------------------------------+ // -// $Id: array_uintersect_uassoc.php,v 1.4 2004/08/28 09:14:07 aidan Exp $ +// $Id: array_uintersect_uassoc.php,v 1.5 2004/08/31 10:46:05 aidan Exp $ /** @@ -25,9 +24,8 @@ * @category PHP * @package PHP_Compat * @link http://php.net/function.array_uintersect_uassoc - * @author Tom Buskens <ortega@php.net> * @author Aidan Lister <aidan@php.net> - * @version $Revision: 1.4 $ + * @version $Revision: 1.5 $ * @since PHP 5 * @require PHP 4.0.1 (trigger_error) */ @@ -35,30 +33,19 @@ { function array_uintersect_uassoc() { - // Get arguments $args = func_get_args(); - if (count($args) < 3) { trigger_error('wrong parameter count for array_uintersect_uassoc()', E_USER_WARNING); return; } - // Get callback functions - $user_func_item = array_pop($args); - $user_func_key = array_pop($args); - - if (is_array($user_func_item) && count($user_func_item) === 2) { - $user_func_item = current($user_func_item) . '::' . current($user_func_item); - } - if (!is_callable($user_func_item)) { - trigger_error('array_uintersect_uassoc() Not a valid callback ' . $user_func_item, E_USER_WARNING); - return; - } - if (is_array($user_func_key) && count($user_func_key) === 2) { - $user_func_key = current($user_func_key) . '::' . current($user_func_key); - } - if (!is_callable($user_func_key)) { - trigger_error('array_uintersect_uassoc() Not a valid callback ' . $user_func_key, E_USER_WARNING); + // Get compare function + $compare_func = array_pop($args); + if (!is_callable($compare_func)) { + if (is_array($compare_func)) { + $compare_func = $compare_func[0] . '::' . $compare_func[1]; + } + trigger_error('array_uintersect_uassoc() Not a valid callback ' . $compare_func, E_USER_WARNING); return; } @@ -68,7 +55,7 @@ for ($i = 0; $i !== $array_count; $i++) { if (!is_array($args[$i])) { - trigger_error('array_uintersect_uassoc() [...]: Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); + trigger_error('array_uintersect_uassoc() Argument #' . ($i + 1) . ' is not an array', E_USER_WARNING); return; } @@ -77,22 +64,14 @@ // Compare entries $output = array(); foreach ($args[0] as $key => $item) { - for ($i = 1; $i !== $array_count; $i++) { - - $array = $args[$i]; - - foreach($array as $key0 => $item0) { - - if (!call_user_func($user_func_key, $key, $key0) && - !call_user_func($user_func_item, $item, $item0)) { - - $output[$key] = $item; - - } - + if (array_key_exists($key, $args[$i])) { + $compare = call_user_func($compare_func, $item, $args[$i][$key]); + if ($compare === 0) { + $output[$key] = $item; + } } - } + } } return $output;
« previous php.pear.cvs (#23522) next »