Kamis, 09 Oktober 2014

switch-case_angka

 this code program is determine number 0-3 and 4-7,
and then if you input number over 7
It will come out the info that the inputted number was outside




<?php
@$x = $_POST['nilai'];
?>
<html>
    <body>
        <form action="#" method="POST">
            <table>
                <h1>Switch_case dengan angka</h1>
                <tr>
                    <td>Masukkan angka</td>
                    <td>:</td>
                    <td><input type="text" name="nilai" value="<?php echo $x; ?>"/></td>
                </tr>
                <tr>
                    <td></td>
                    <td></td>
                    <td><input type="submit" name="proses" value="Kirim"/></td>
                </tr>
            </table>
        </form>
        <?php
        switch ($x) {
            case 0 :
            case 1 :
            case 2 :
            case 3 :
                echo "Angka berada di dalam range 0-3";
                break;
            case 4 :
            case 5 :
            case 6 :
            case 7 :
                echo "Angka berada di dalam range 4-7";
                break;
            default :
                echo "Angka diluar jangkauan";
                break;
        }
        ?>
    </body>
</html>

Tidak ada komentar:

Posting Komentar