assoc在php中,在PHP中使用array_diff_assoc函数

您总是可以从阅读PHP手册开始。

对于array_diff_assoc(在http://php.net/manual/en/function.array-diff-assoc.php上),据说是this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using, for example, array_diff_assoc($array1[0], $array2[0]);.

在用户评论中提供了解决方案(这确实有效):

55 dot php at imars dot com

17-Mar-2009 03:09 I've worked on

array_diff_assoc_recursive() mentioned

by chinello at gmail dot com and I

think it might be worth mentioning

here. I wrote a dozen test cases and

it seems to be holding up pretty well.

// dwarven Differences:

// * Replaced isset() with array_key_exists() to account for keys with null contents

// 55 dot php at imars dot com Differences:

// Key differences:

// * Removed redundant test;

// * Returns false bool on exact match (not zero integer);

// * Use type-precise comparison "!==" instead of loose "!=";

// * Detect when $array2 contains extraneous elements;

// * Returns "before" and "after" instead of only "before" arrays on mismatch.

function array_compare($array1, $array2) {

$diff = false;

// Left-to-right

foreach ($array1 as $key => $value) {

if (!array_key_exists($key,$array2)) {

$diff[0][$key] = $value;

} elseif (is_array($value)) {

if (!is_array($array2[$key])) {

$diff[0][$key] = $value;

$diff[1][$key] = $array2[$key];

} else {

$new = array_compare($value, $array2[$key]);

if ($new !== false) {

if (isset($new[0])) $diff[0][$key] = $new[0];

if (isset($new[1])) $diff[1][$key] = $new[1];

};

};

} elseif ($array2[$key] !== $value) {

$diff[0][$key] = $value;

$diff[1][$key] = $array2[$key];

};

};

// Right-to-left

foreach ($array2 as $key => $value) {

if (!array_key_exists($key,$array1)) {

$diff[1][$key] = $value;

};

// No direct comparsion because matching keys were compared in the

// left-to-right loop earlier, recursively.

};

return $diff;

};

?>

1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下 4载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合;、下载 4使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值