PHP简单计算器

工作之余,写着玩的。

 

<?php 
        $num1 = $_POST['num1'];
        $num2 = $_POST['num2'];
        $yusuan = $_POST['yusuan'];
        $jieguo = 0;
        switch($yusuan){
            case '+': $jieguo = $num1 + $num2;break;
            case '-': $jieguo = $num1 - $num2;break;
            case '*': $jieguo = $num1 * $num2;break;
            case '/': $jieguo = $num1 / $num2;break;
        }
    ?>
    <form action="" method="post">
        <table align="center" border="1">
            <tr>
                <td><input type="text" name="num1" value="<?php echo $num1; ?>"/></td>
                <td>
                    <select name="yusuan">
                        <option value="+" <?php if($yusuan=="+"){echo 'selected="select"';} ?>">+</option>
                        <option value="-" <?php if($yusuan=="-"){echo 'selected="select"';} ?>">-</option>
                        <option value="*" <?php if($yusuan=="*"){echo 'selected="select"';} ?>">*</option>
                        <option value="/" <?php if($yusuan=="/"){echo 'selected="select"';} ?>">/</option>
                    </select>
                </td>
                <td><input type="text" name="num2" value="<?php echo $num2; ?>"/></td>
                <td><input type="submit" value="="/></td>
                <td><input type="text" name="jieguo" value="<?php echo $jieguo;?>"/></td>
            </tr>
        </table>
    </form>

 

posted @ 2015-09-12 08:56  木子小僧  阅读(1967)  评论(0编辑  收藏  举报