![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 1 Pomógł: 0 Dołączył: 8.05.2021 Ostrzeżenie: (0%) ![]() ![]() |
Prosił bym o pomoc.
Posiadam dwie tablice. Sprzedaż i zakup. Muszę sprawdzić dla każdego elementu "SKU" w tablicy zakupów, czy nastąpiła sprzedaż. Jeśli tak, to efektem tego powinna być nowa tablica $tmp, ze zmodyfikowanym stanem "count". Z góry dziękuję za pomoc. $boughtProducts = array( array("SKU"=>"0001", "count"=>10, "Joe"=>"43"), array("SKU"=>"0002", "count"=>8, "Joe"=>"43"), array("SKU"=>"0003", "count"=>10, "Joe"=>"43") ); $soldProducts = array( array("SKU"=>"0001", "count"=>10, "Joe"=>"43"), array("SKU"=>"0002", "count"=>2, "Joe"=>"43"), array("SKU"=>"0003", "count"=>0, "Joe"=>"43") ); $tmp= array( array("SKU"=>"0001", "count"=>10, "Joe"=>"43"), array("SKU"=>"0002", "count"=>6, "Joe"=>"43"), array("SKU"=>"0003", "count"=>0, "Joe"=>"43") ); Dla zainteresowanych. Rozwiązałem problem. $boughtProducts = array( array("SKU"=>"0001", "count"=>10, "Joe"=>"43"), array("SKU"=>"0002", "count"=>8, "Joe"=>"43"), array("SKU"=>"0003", "count"=>10, "Joe"=>"43") ); $soldProducts = array( array("SKU"=>"0003", "count"=>2, "Joe"=>"43"), // array("SKU"=>"0002", "count"=>2, "Joe"=>"43"), array("SKU"=>"0001", "count"=>5, "Joe"=>"43") ); $items = count($boughtProducts); $itemsb = count($soldProducts); $result = $boughtProducts; for($i = 0; $i < $items; $i++) { $b=0; if($result[$i]["SKU"] != $soldProducts[$b]['SKU']) { for($b = 0; $b < $itemsb; $b++){ if ($soldProducts[$b]['SKU'] == $result[$i]["SKU"]) { $result[$i]["count"] = ($boughtProducts[$i]['count'] - $soldProducts[$b]['count']); } } }else{ $result[$i]["count"] = ($boughtProducts[$i]['count'] - $soldProducts[$b]['count']); } } echo "<pre>"; print_r($result); echo "</pre>"; Ten post edytował rafal75 12.05.2021, 20:07:58 |
|
|
![]() |
![]()
Post
#2
|
|
![]() Grupa: Zarejestrowani Postów: 8 068 Pomógł: 1414 Dołączył: 26.10.2005 Ostrzeżenie: (0%) ![]() ![]() |
A może tak...
|
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 14.08.2025 - 14:58 |