dev-master
9999999-dev https://github.com/AAstakhov/array-diffComponent for calculating difference of arrays
MIT
The Requires
- php >=5.5 || ^7.0
- symfony/yaml 2.* || 3.*
The Development Requires
Component for calculating difference of arrays
ArrayDiff Calculator works similar to a php function array_diff_assoc
but calculates a difference of arrays in a better way due to:, (*2)
Example, (*3)
$array1 = ['a' => 8, 'b' => 2, 'c' => 3]; $array2 = ['a' => 6, 'b' => 2, 'd' => 3]; $calc = new Calculator(new SimpleMatcher()); $diff = $calc->calculateDiff($array1, $array2); print $diff->toString();
outputs:, (*4)
missing: - key_path: c expected: 3 unmatched: - key_path: a expected: 8 actual: 6
because, (*5)
Advanced example, (*6)
Let's assume we have two arrays:, (*7)
$array1 = [
'name' => '
|
$array2 = [
'name' => 'The Lord of the Rings',
'price' => '25.99 EUR',
'in_stock' => true,
'isbns' => [
'isbn-10' => '1230260002385',
],
'pages' => 567,
];
|
You can calculate a difference of these arrays using an expression matching:, (*8)
$calc = new Calculator(new ExpressionMatcher()); $diff = $calc->calculateDiff($array1, $array2); print $diff->toString();
It returns:, (*9)
missing: { } unmatched: - key_path: pages expected: '<type.datetime>' actual: 567
because, (*10)
<type.string>
<type.float(2)> <type.string>
<type.boolean>
<type.string>
<type.datetime>
Expressions have syntax <expresion-name(param1, param2,...)>
., (*11)
Component for calculating difference of arrays
MIT