title: Calculate monthly package (product) price in php
body: <p><br>
  I've created e-commerce website, It's about to deliver lunch and dinner service. I am putting question/problem here because i know <strong>here are a lot of legends who can help me.</strong> I have added packages/plan section in website.</p>
  
  <pre><code> 1. Weekly
   2. Monthly
  </code></pre>
  
  <p><strong>Here is the screenshot of page questions form of ordering product:</strong>
  <a href="https://i.stack.imgur.com/QY6d6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QY6d6.png" alt="enter image description here"></a><br>
  I can easy calculate weekly price like if product price 100 and user selected weekly plan and he choose days from monday to saturday (6 days in a week only), then we can easy calculate price with <code>6*100 = 600</code>.<br>
  But what about calculating monthly price?<br>
  <strong>For example:</strong> If user selected monthly plan and choose 6 days in a week from Monday to Saturday or whatever he wants to choose days names. Then he place his order. Now,<br></p>
  
  <pre><code>6 * 4 = 24 (6 days * 4 weeks)
  24 * 100 = 2400 (days * product price)
  </code></pre>
  
  <p>But it's only calculating for 4 weeks, not of full month. I wanna calculate full month. If i check that current month is of 30 days then <code>4 (weeks) + 2 days</code> and if current month is of 31 days then <code>4 (weeks) + 3 days</code>. Looks like simple and done,  but it's dangerous also, coz what if that + 2 or +3 days are those days which user has unchecked during ordering monthly package.<br>
  <strong>Here is my code:</strong></p>
  
  <pre><code>&lt;?php
      $pCartProducts = $pcart-&gt;getPlanCartProducts($userid);
  ?&gt;
  
  &lt;tbody&gt;
      &lt;?php
          if($pCartProducts){
              $finalPrice = 0;
              while($pcPro = $pCartProducts-&gt;fetch_assoc()){
                  $planName = $pcPro['plan_name'];
      ?&gt;
  
      &lt;tr&gt;
          &lt;td data-title="Plan"&gt;
              &lt;?php echo $planName; ?&gt;
          &lt;/td&gt;
          &lt;?php 
  
              $pro_price = $pcPro['pro_price'];
              $plan_days = $pcPro['plan_days']; // if user selected 6 days in a week
              $totaldays = $plan_days * 4; // 6 * 4 weeks = 24
  
              // Calculating current month days
              $month = date('m');
              $year = date('Y');
              $cal_days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
  
              if($planName == 'Weekly'){
  
                  $total_price = $pro_price * $plan_days;
  
              } elseif($planName == 'Monthly'){
  
                  if($cal_days == '30'){
                       $final_tdays = $totaldays + 2; // + 2 days
                  } elseif($cal_days == '31'){
                      $final_tdays = $totaldays + 3;  // + 3 days
                  } elseif($cal_days == '29'){
                      $final_tdays = $totaldays + 1;  // + 1 day
                  } elseif($cal_days == '28'){
                      $final_tdays = $totaldays;      // normal
                  }
  
                  $total_price = $final_tdays * $pro_price; // final days * product price
  
              }
  
          ?&gt;
          &lt;td data-title="Price"&gt;
              &lt;span&gt;Rs./&lt;?php echo $total_price; ?&gt;&lt;/span&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;?php } } ?&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p><strong>Additional Screenshots:</strong>
  <a href="https://i.stack.imgur.com/XVYmb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XVYmb.png" alt="enter image description here"></a><br>
  <a href="https://i.stack.imgur.com/22arf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/22arf.png" alt="enter image description here"></a><br></p>
  
  <p>Can someone please help me to calculate monthly price with selected days in a week?
  <strong>Please help me</strong></p>