l!m!t Posted April 9, 2010 Share Posted April 9, 2010 Hello, I am trying to create a table rate discount function, which is based on quantity - Right now I have it so it discounts using the following method - 20:10, 50:20 which comes out to 20 items = 10% off , 50 items = 20% off . I want to re-write it so I can define the qty discount like ( 20 - 50:10, 50-100:20 ) which comes out to - 20 through 50 items = 10% off , 50 - 100 items = 20% off. ) I have been at it for hours, I figure perhaps somebody can give some input on this. This is acutally a function which is looped, but I have hard coded the values for the demo. Any help would be appreciated. My snippet is below. $products_price='5.99'; $qty_table_rate= '20:10, 50:20'; $qd_qty='10'; $qty_table_cost = split("[:,]", '$qty_table_rate); $size = sizeof($qty_table_cost); for ($i = 0, $n = $size; $i < $n; $i += 2) { if ($qd_qty <= $qty_table_cost[$i]) { $qty_discount = $qty_table_cost[$i + 1]; $qd_price = $products_price * $qty_discount / 100; break; } } Link to comment https://forums.phpfreaks.com/topic/198092-explode-split-help-please/ Share on other sites More sharing options...
l!m!t Posted April 9, 2010 Author Share Posted April 9, 2010 I figured it out - I just used the php explode function to split the dash and then put into two separate arrays explode('-',$foobar ,2); Maybe it will help somebody else. Link to comment https://forums.phpfreaks.com/topic/198092-explode-split-help-please/#findComment-1039367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.