PHP: Bir hesaplama için bazı kullanım-mümkün değere dakika içinde dönüştürme kullanıcı girişi

1 Cevap

Overall goal: User enters some number in minutes and I change those numbers from minutes to some usable form in a calculation.

Nasıl kullanıcı girişi bu php script daha sonra kullanabileceğiniz bazı numarasına veya değere dakika şeklinde dönüştürebilirim?

<?php
$minutes = $_REQUEST["minutes"];
// We initialize the total to $1.99 for the connection fee: 
$total  = 1.99;
// For each additional minute we add $0.45?
// For example if  3 minutes are used the cost = $2, 
$addmin = 0.45;
/* How do I convert the user inputted minutes to some value
 I can manipulate with php so that I can just add via php and give the user 
 a cost, for example,  3minutes entered into a form might be = cost of $2.
 What do I need to read or study?*/
//We use a if statement here:
if (filter_has_var(INPUT_POST, "minutes"))
{
// If the user selects the number of minutes, we echo out the number of minutes.
print $minutes;
print "mins.";
// Condition pending  here: 
$total += filter_input(INPUT_POST, "$addmin");
}
print "<p>The total cost is: \$$total</p> \n";
?>

1 Cevap

Dakika bir hesaplama için zaten sayısının kullanılabilir bir form vardır. Eğer bir hesaplamada $ dakika değişken kullanırsanız otomatik olarak bir dizi döküm olmalıdır.

// $minutes = 3, $addmin = 0.45, 3 * 0.45 = 1.35
$subtotal = $minutes * $addmin;
$total   += $subtotal;

2 $ olmak üzere ilk 3 dakika istedim ve sonra her ek dakikada 0,45 $ olması durumunda, aşağıdaki gibi bir şey yapmak istiyorum:

$subtotal = 0;
// If less than 3 minutes were input, use 3 minutes anyway.
$minutes  = $minutes < 3 ? 3 : $minutes;  
if ($minutes >= 3)  // If minutes
{
    $minutes -= 3;
    $subtotal = 2;
}

// multiple the remaining minutes by the additional cost
$subtotal += $minutes * $addmin;
$total    += $subtotal;