【发布时间】:2017-11-05 11:26:48
【问题描述】:
我是 php 新手,我已经阅读了关于 php.net、w3schools 和其他资源上的 array_diff_uassoc() 函数的文档在互联网上,但未能得到这个功能的用途。在我看来,这是无意义的功能,因为它的文档非常混乱。
据我所知,第一个参数和第二个参数是数组,但是第三个参数的作用是函数,它必须返回小于、大于或等于 0 以及 this 和 this。这个无意义的文档是什么意思?
按照所有示例生成相同的结果。
示例 1
function test($a,$b){
$a > $b ? 1 : -1;
}
$arrayOne = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$arrayTwo = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$x = array_diff_uassoc($arrayOne,$arrayTwo,'test');
输出
数组 ( [二] => 元素二 [三] => 元素三 )
示例 2
function test($a,$b){
$a > $b ? -1 : 1;
}
$arrayOne = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$arrayTwo = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$x = array_diff_uassoc($arrayOne,$arrayTwo,'test');
输出
数组 ( [二] => 元素二 [三] => 元素三 )
示例 3
function test($a,$b){
$a < $b ? 0 : 1;
}
$arrayOne = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$arrayTwo = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$x = array_diff_uassoc($arrayOne,$arrayTwo,'test');
输出
数组 ( [二] => 元素二 [三] => 元素三 )
示例 4
function test($a,$b){
$a < $b ? 0 : 1;
}
$arrayOne = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$arrayTwo = array(
"one"=>"elementOne",
"two"=>"elementTwo",
"three"=>"elementThree"
);
$x = array_diff_uassoc($arrayOne,$arrayTwo,'test');
输出
数组 ( [二] => 元素二 [三] => 元素三 )
那么这个无意义的函数是什么意思呢?谁能告诉我或者可能是我错了?
【问题讨论】:
-
您的
test函数不符合您列出的规则。你不应该期望它有正确的结果。仅仅因为你不理解它们就小心地将它们标记为“废话”,这不是学习的最佳方式 -
那么我应该遵循与互联网上记录的相同的文档吗?
-
请您在单独的答案中举几个例子吗?如果清楚我的概念,我会标记你的问题。
-
The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.: 如果PHPDocs page 说用户回调函数应该返回一个值,那么你的回调函数返回一个值总是一个好主意 -
请不要在评论中提供大纲。请用示例单独回答