Example scenario
I have 2 different data arrays, sorted by chaveN
and chaveF
.
The goal is to compare the 2 arrays, differentiating what you have in the array docs with the array frts , but strong> docs without the related in frts , and vice versa .
You may also have frts records that are related to several docs , and this should have value for the sum of > fret docs .
Basically it would be a UNION ALL
comparing them.
The "connection" would be: docs.chaveN = frts.chaveN
Array example
Array docs
:
$docs = array(
0 => array("chaveN" => 1, "doc" => 1010, "valor" => 10.10, "frete" => 1.10),
1 => array("chaveN" => 2, "doc" => 2020, "valor" => 20.10, "frete" => 2.10),
2 => array("chaveN" => 3, "doc" => 3030, "valor" => 30.10, "frete" => 3.10),
3 => array("chaveN" => 5, "doc" => 4040, "valor" => 40.10, "frete" => 4.10),
4 => array("chaveN" => 7, "doc" => 5050, "valor" => 50.10, "frete" => 5.10),
5 => array("chaveN" => 8, "doc" => 7070, "valor" => 70.10, "frete" => 7.10),
6 => array("chaveN" => 9, "doc" => 8080, "valor" => 80.10, "frete" => 8.10),
7 => array("chaveN" => 10, "doc" => 9090, "valor" => 90.10, "frete" => 9.10),
8 => array("chaveN" => 11, "doc" => 1100, "valor" => 70.10, "frete" => 7.10),
9 => array("chaveN" => 12, "doc" => 1200, "valor" => 80.10, "frete" => 8.10),
10 => array("chaveN" => 13, "doc" => 1300, "valor" => 90.10, "frete" => 9.10)
);
Array frts
:
$frts = array(
0 => array("chaveF" => 'F1', "chaveN" => 1, "valor" => 1.10),
1 => array("chaveF" => 'F2', "chaveN" => 2, "valor" => 2.10),
2 => array("chaveF" => 'F3', "chaveN" => 3, "valor" => 3.10),
3 => array("chaveF" => 'F4', "chaveN" => 4, "valor" => 4.10),
4 => array("chaveF" => 'F9', "chaveN" => array
(0 => 7, 1 => 8, 2 => 9),
"valor" => 24.30),
5 => array("chave" => 'F10', "chaveN" => array
(0 => 10, 1 => 11, 2 => 12),
"valor" => 24.25),
7 => array("chaveF" => 'F7', "chaveN" => 20, "valor" => 4.10)
);
Note that frts 5
, the sum of the value , does not match the freight keyN referers
Example of expected result
Questions
- Should I start by treating the arrays?
- What native array functions could you use for all of this ordering?