checkPrice - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of checkPrice.php

  1. <?php
  2.  
  3. $total = 75;
  4.  
  5. $free = 25;
  6.  
  7. $paid = 10;
  8.  
  9. $price = 25;
  10.  
  11.  
  12. //===================
  13.  
  14.  
  15. $unpaid = max( $total - ($paid + $free), 0);
  16.  
  17.  
  18.  
  19. if($total <= $free) {
  20.        
  21.         $toPay = 0;
  22.        
  23. }
  24.  
  25. else if($total > $free && $total <= 100) {
  26.        
  27.         if($paid > $price) {
  28.                
  29.                 $toPay = 0;
  30.                
  31.         } else {
  32.                
  33.                 $toPay = $price;
  34.                
  35.         }
  36.        
  37. }
  38.  
  39. else {
  40.        
  41.         if($paid < 100) {
  42.                
  43.                 $toPay =  (ceil( ($unpaid - 100) / 50) + 1) * $price ;
  44.                
  45.         } else {
  46.                
  47.                 $toPay = (ceil( $unpaid / 50 ) ) * $price;
  48.         }
  49.        
  50. }
  51.  
  52.  
  53.  
  54. print_r( ['total' => $total, 'paid' => $paid, 'unpaid' => $unpaid, 'toPay' => $toPay] );
File Description
  • checkPrice
  • PHP Code
  • 04 Feb-2021
  • 553 Bytes
You can Share it: