Rabu, 08 Oktober 2014

Switch-case rasa buah

this opportunity i will share to  determines the taste of fruits using
switch-case ,
here i will input the name of fruit and the result is flavor of the fruits



<?php
@$x = $_POST['buah'];
?>
<html>
    <body>
        <form action="#" method="POST">
            <table>
                <h1>Switch_case dengan string menentukan buah manis atau asam</h1>
                <tr>
                    <td>Masukkan angka</td>
                    <td>:</td>
                    <td><input type="text" name="buah" 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 "mangga":echo "asam";
                break;
            case "jeruk": echo"manis";
                break;
            case"pisang":echo"manis";
                break;
            case "manggis":echo"asam dan manis";
                break;
            case "anggur":echo"manis";
                break;
            case "apple": echo"manis";
                break;
            case"langsat":echo"asam";
                break;
            case "semangka":echo"manis";
                break;
            case "nenas": echo"asam";
                break;
            case"jambu": echo"manis";
                break;
            default :echo"buah yang dimasukkan tidak ada di dalam daftar, silahkan coba yang lain";
        }
        ?>
    </body>
</html>

Tidak ada komentar:

Posting Komentar