Mecha CMS

Helper functions.

j

Compares first array against second array and returns the values in first array that are not present in the second array.

2.0.02.2.0

j(array $a, array $b);

Example:

// Difference on Level 1
$a = ['a' => ['b' => ['c' => 'c']], 'd' => 'd'];
$b = ['a' => ['b' => ['c' => 'c']]];
$diff = j($a, $b); // ['d' => 'd']

// Difference on value on Level 3
$a = ['a' => ['b' => ['c' => 'c']], 'd' => 'd'];
$b = ['a' => ['b' => ['c' => 'x']], 'd' => 'd'];
$diff = j($a, $b); // ['a' => ['b' => ['c' => 'c']]]

// Difference on key on Level 3
$a = ['a' => ['b' => ['c' => 'c']], 'd' => 'd'];
$b = ['a' => ['b' => ['x' => 'c']], 'd' => 'd'];
$diff = j($a, $b); // ['a' => ['b' => ['c' => 'c']]]

// No differences even if Level 2 of $b has an extra item
$a = ['a' => ['b'=> ['c' => 'c']], 'd' => 'd'];
$b = ['a' => ['b'=> ['c' => 'c'], 'x' => 'x'], 'd' => 'd'];
$diff = j($a, $b); // []

// No differences even if Level 3 of $b has an extra item because
// $b has all the $a keys and values
$a = ['a' => ['b'=> ['c' => 'c']], 'd' => 'd'];
$b = ['a' => ['b'=> ['c' => 'c', 'x' => 'x']], 'd' => 'd'];
$diff = j($a, $b); // []