堡垒 / 数组比较
比较两个数组并返回差异
1.0.0
2022-07-22 15:26 UTC
Requires
- php: ^8.1
Requires (Dev)
- infection/infection: ^0.26.13
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.3
- squizlabs/php_codesniffer: ^3.7
README
比较两个关联数组并查看它们之间的差异。
支持嵌套关联数组和数组集合。
安装
您可以通过composer安装此包
composer require fortress/array-comparison
用法
$expected = [ 'object' => [ 'to_be_removed' => [ 'item1', 'item2', ], 'to_be_changed' => [ 'item3', 'item4', ] ] ]; $actual = [ 'object' => [ 'to_be_added' => [ 'item3', 'item4', ], 'to_be_changed' => [ 'item5', 'item6', ], ] ]; $comparison = new Fortress\ArrayComparison(); $comparison->getDiff($expected, $actual);
结果为
[
'added' => [
'object' => [
'to_be_added' => [
'item3',
'item4',
],
]
],
'removed' => [
'object' => [
'to_be_removed' => [
'item1',
'item2',
],
]
],
'changed' => [
'object' => [
'to_be_changed' => [
'old' => [
'item3',
'item4',
],
'new' => [
'item5',
'item6',
],
],
],
],
]
测试
composer test
许可证
MIT许可证(MIT)。请参阅许可证文件获取更多信息。