Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function updateList(array $list) {
- foreach($list['currentList'] as $currentEntry => $currentVal) {
- foreach($list['newList'] as $newEntry => $newVal) {
- // we have a hit
- if ($currentEntry == $newEntry) {
- $list['newList'][$newEntry] += $list['currentList'][$currentEntry];
- continue 2;
- }
- // last entry hit
- if ($newEntry == end(array_keys($list['newList']))) {
- array_push($list['newList'][$currentEntry], $currentEntry);
- $list['newList'][$currentEntry] = $currentVal;
- }
- }
- }
- return $list['newList'];
- }
- // Testing
- $InventoryList = array(
- 'currentList' => array(
- 'Chicken' => 2,
- 'Pork' => 3,
- 'Ginisa Mix' => 1,
- 'Tissue Roll' => 3,
- 'Beef' => 5 ),
- 'newList' => array(
- 'Chicken' => 3,
- 'Beef' => 2,
- 'Beer' => 3,)
- );
- print_r(updateList($InventoryList));
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement