开发者

Change a number of products to a product pack

开发者 https://www.devze.com 2023-04-10 06:37 出处:网络
I have this problem : i\'m working on a small e-shop and I have about 60 products in the database . all the products have a code , like : 4444, 5334, 3244 and so on . The problem is that there are als

I have this problem : i'm working on a small e-shop and I have about 60 products in the database . all the products have a code , like : 4444, 5334, 3244 and so on . The problem is that there are also product packs and they are made out of several products .

I have to do th开发者_StackOverflow社区is : everytime there is an update to the CART there must be a script checking if the products in CART can make a PRODUCT PACK and replace all the products from the CART with that product pack .

What do you think would be the best way to do this check / change ?


Assuming $packs is an array of arrays of items, and $cart is an array of items:

foreach($packs as $pack) {
    $diff = array_diff($pack, $cart);
    if (empty($diff)) {
        // $cart contains this pack
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消