php计算器根据输入切换乘数

时间:2015-06-29 11:37:02

标签: php

您好我正在使用php构建一台简单的计算机 它的工作方式应该是当用户选择大于30的数字时,变量(在这种情况下为m1)变为m2,依此类推。
我怎么能做到这一点?
提前谢谢

<?php
    $m1 = 5 /*prezzo della  maglia -  price 1*/;
    $m2 = 2;/*price   when quantity is over a number*/
    $m3 = 1;/*price   when quantity is over a number*/

    $s1 = 3; /*price of print 1*/
    $s1 = 3; /*price of print 1 if quantity change*/

    $bxs = $_GET['bxs'];
    $bs = $_GET['bs'];
    $bm = $_GET['bm'];
    $bl = $_GET['bl'];
    $bxl = $_GET['bxl'];
    $b2xl = $_GET['b2xl'];
    /*riga del nero*/
    $nxs = $_GET['nxs'];
    $ns = $_GET['ns'];
    $nm = $_GET['nm'];
    $nl = $_GET['nl'];
    $nxl = $_GET['nxl'];
    $n2xl = $_GET['n2xl'];

$somma = $m1*($bxs+$bs+$bm+$bl+$bxl+$b2xl+$nxs+$ns+$nm+$nl+$nxl+$n2xl);
?>

1 个答案:

答案 0 :(得分:1)

这很简单,但您必须提供用户输入该值的方式。

例如,通过GET参数number
    $userInput = $_GET['number'];

然后你只需要创建基本的if语句。您可以在http://php.net/manual/en/control-structures.if.php

了解相关信息
$somma = $bxs+$bs+$bm+$bl+$bxl+$b2xl+$nxs+$ns+$nm+$nl+$nxl+$n2xl;
if($userInput <= 30){
    $somma *=$m1;
}else if($userInput >30) {
    $somma *=$m2;
} else if($userInput > 8779){ // your number : )
    $somma *=$m3;
}