Jump to content

Explode / Split = Help Please


l!m!t

Recommended Posts

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.