harshmaan991
New member
I expected 4 items to arrive. Here are the SKU numbers:
1111
2222
2222
3333
When the box arrived and I opened it, I found these SKU numbers:
1111
2222
3333
3333
Upon opening the box, I immediately saw:
• SKU 2222 was missing
• there was an extra SKU 3333
My simple PHP script correctly shows the missing SKUs and the reconciled SKUs..... but why is it not showing the extra SKU?
1111
2222
2222
3333
When the box arrived and I opened it, I found these SKU numbers:
1111
2222
3333
3333
Upon opening the box, I immediately saw:
• SKU 2222 was missing
• there was an extra SKU 3333
My simple PHP script correctly shows the missing SKUs and the reconciled SKUs..... but why is it not showing the extra SKU?
PHP:
<?php
$expected = array(
'1111',
'2222',
'2222',
'3333'
);
$received = array(
'1111',
'2222',
'3333',
'3333'
);
$expected = array_filter($expected);
$received = array_filter($received);
$expected_counts = array_count_values($expected);
$received_counts = array_count_values($received);
$not_received = array();
$reconciled = array();
$extra = array();
foreach ($expected_counts as $sku => $expected_count) {
if (isset($received_counts[$sku])) {
if ($received_counts[$sku] >= $expected_count) {
$reconciled = array_merge($reconciled, array_fill(0, $expected_count, $sku));
} else {
$reconciled = array_merge($reconciled, array_fill(0, $received_counts[$sku], $sku));
$not_received = array_merge($not_received, array_fill(0, $expected_count - $received_counts[$sku], $sku));
}
} else {
$not_received = array_merge($not_received, array_fill(0, $expected_count, $sku));
}
}
foreach ($received_counts as $sku => $received_count) {
if (!isset($expected_counts[$sku])) {
$extra = array_merge($extra, array_fill(0, $received_count, $sku));
}
}
// Output the results
print_r($not_received); // SKUs that are missing
print_r($reconciled); // SKUs that reconcile
print_r($extra); // EXTRA (unexpected) SKUs
?>