X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Array Question (https://forum.x-cart.com/showthread.php?t=4132)

machnhed1 08-26-2003 12:11 PM

Array Question
 
Hi Everyone,

I have this array:
Code:

Array
(
    [0] => Array
        (
            [productid] => 16141
            [amount] => 1
        )

    [1] => Array
        (
            [productid] => 129
            [amount] => 1
        )

    [2] => Array
        (
            [productid] => 16141
            [amount] => 1
        )

)

I was wondering if there was a function that would take the values of the array and add up the amounts or identical productids so that the result would look something like this:
Code:

Array
(
    [0] => Array
        (
            [productid] => 16141
            [amount] => 2
        )

    [1] => Array
        (
            [productid] => 129
            [amount] => 1
        )


)


I looked on php.net, but either I am missing it or it doesn't exist. Hopefully someone knows how to do this.

Thanks :!:

funkydunk 08-27-2003 03:13 AM

Hi,

If you look within cart.php there is already a function there that does this kind of thing.

I guess you are looking to do an add multiple products to cart or something.

If you are it is easier to add all the products/amounts to the array that you are referring to then loop through the cart.php for each element of the array - this will sort the add multiple products side for you plus look at the product options elements aswell.

machnhed1 08-27-2003 05:09 AM

FD,

Actually I am making a module that compares what you have in your cart to what people have bought in the past and then recommends products you should consider. I am thinking that I'll put it on the cart.php page and the individual products page.

Thanks for the tip :!:


All times are GMT -8. The time now is 09:50 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.