Bug #64655 [Opn->Fbk]: array_diff_uassoc bug.
Edit report at https://bugs.php.net/bug.php?id=64655&edit=1
ID: 64655
Updated by: laruence@php.net
Reported by: jeoe12 at gmail dot com
Summary: array_diff_uassoc bug.
-Status: Open
+Status: Feedback
Type: Bug
Package: PHP options/info functions
Operating System: Ubuntu
PHP Version: 5.3Git-2013-04-17 (snap)
Block user comment: N
Private report: N
New Comment:
actually, I can not understand what the bug you are talking about.....
could you please give us a simple test script, and also the expect result
Previous Comments:
------------------------------------------------------------------------
[2013-04-17 09:57:21] jeoe12 at gmail dot com
Description:
------------
array_diff_uassoc bug..
this function is diff args[0] to args[n-1]
* args[n] == "user function"
if (args[0].value == args[n-1].value)
==> run to "user function"
but..
PHP Version 5.3.5-1ubuntu7.7
not run...
Test script:
---------------
function key_compare_func($key1, $key2)
{
echo $key1. " ". $key2 . "<br>";
if ($key1 == $key2)
return 0;
else if ($key1 > $key2)
return 1;
else
return -1;
}
$array1 = array('1-1' => 1, '1-2' => 2, '1-3' => 3,
'1-4' => 4);
$array2 = array('2-1' => 5, '2-2' => 6, '2-3' => 7,
'2-4' => 8);
var_dump(array_diff_uassoc2($array1, $array2, 'key_compare_func'));
Expected result:
----------------
function php_compat_array_diff_uassoc()
{
$args = func_get_args();
if (count($args) < 3) {
user_error('Wrong parameter count for array_diff_uassoc()', E_USER_WARNING);
return;
}
$compare_func = array_pop($args);
if (!is_callable($compare_func)) {
if (is_array($compare_func)) {
$compare_func = $compare_func[0] . '::' . $compare_func[1];
}
user_error('array_diff_uassoc() Not a valid callback ' .
$compare_func, E_USER_WARNING);
return;
}
$array_count = count($args);
for ($i = 0; $i !== $array_count; $i++) {
if (!is_array($args[$i])) {
user_error('array_diff_uassoc() Argument #' .
($i + 1) . ' is not an array', E_USER_WARNING);
return;
}
}
$result = array();
foreach ($args[0] as $k => $v) {
for ($i = 1; $i < $array_count; $i++) {
foreach ($args[$i] as $kk => $vv) {
if ($v == $vv) {
$compare = call_user_func_array($compare_func, array($k, $kk));
if ($compare == 0) {
continue 3;
}
}
}
}
$result[$k] = $v;
}
return $result;
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64655&edit=1
Thread (3 messages)