loki421

11-19-2011, 02:27 PM

Hi guys and gals!

Must be having that wekend feeling because I just can't seem to figure out the best way to do this..

So here's what I'm struggling with, I have a multi-dimentional array that looks like this:

Array

(

[0] => Array

(

[id] => 2

[qty] => 1

[size] => XL

[def] => prod_1

)

[1] => Array

(

[id] => 5

[qty] => 1

[size] => XL

[def] => prod_2

)

[2] => Array

(

[id] => 10

[qty] => 1

[size] => L

[def] => prod_7

)

)

Basically that's a very simple version of a cart. What I'm trying to do is apply a discount if two products the same size are found. So in the above example there are two products with the same size (XL), so this would qualify.

If another product was added with a size of large (L) then this would also qualify for a discount as there would be two products with size large in the array as well as two XL products. Hope this makes sense so far?

Ok, so I've tried all sorts of for, foreach and while loops but none are giving me the expected results. I've looked at maybe using array_intersect() but don't think that would work on a multi-demntional array such as this.

Does anyone have any pointers they could offer? I would be very gratefull to see how you peeps would tackle this kind of problem.

Looking forward to any replys :)

Must be having that wekend feeling because I just can't seem to figure out the best way to do this..

So here's what I'm struggling with, I have a multi-dimentional array that looks like this:

Array

(

[0] => Array

(

[id] => 2

[qty] => 1

[size] => XL

[def] => prod_1

)

[1] => Array

(

[id] => 5

[qty] => 1

[size] => XL

[def] => prod_2

)

[2] => Array

(

[id] => 10

[qty] => 1

[size] => L

[def] => prod_7

)

)

Basically that's a very simple version of a cart. What I'm trying to do is apply a discount if two products the same size are found. So in the above example there are two products with the same size (XL), so this would qualify.

If another product was added with a size of large (L) then this would also qualify for a discount as there would be two products with size large in the array as well as two XL products. Hope this makes sense so far?

Ok, so I've tried all sorts of for, foreach and while loops but none are giving me the expected results. I've looked at maybe using array_intersect() but don't think that would work on a multi-demntional array such as this.

Does anyone have any pointers they could offer? I would be very gratefull to see how you peeps would tackle this kind of problem.

Looking forward to any replys :)