[PHP] Steen, papier, schaar

Gestart doorSebastiaanh11 reacties87 weergaven

12 berichten · pagina 1 van 1

Sebastiaanh

Lid · Topicstarter

Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hey,

Ik vond een oud scriptje van mij terug op mijn laptop. yummieHierbij release ik hem maar, heb er verder toch niets aan.

Code:
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*
 * @author: Sebastiaan H
 * @product: Steen, papier, schaar
 */[/COLOR]
 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er gaat iets fout![/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/rand"]rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, het is dus gelijk spel.[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];
        }[/COLOR]        
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt verloren![/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt verloren![/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt verloren![/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];
        }[/COLOR]
        [URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700])
        {[/COLOR]
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];
        }
    }
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>

<form action="#" method="post">
    <select name="keuze">
        <option value="steen">Steen</option>
        <option value="papier">Papier</option>
        <option value="schaar">Schaar</option>
    </select>
    
    <input type="submit" value="Gok" />
</form>

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
Groetjes,
Sebastiaan
0
Berichten
5.274
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien

Eindhoven, Nederland

Je hebt geluk dat het PHP is, anders kreeg je een fout. Een String met een Int matchen. emo
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zoveel elseifs, kan je niet beter een switch gebruiken?
0
Sebastiaanh

Lid · Topicstarter

Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Zoveel elseifs, kan je niet beter een switch gebruiken?
Ja, dat doe ik inmiddels ook, maar ik zei toch dat het een oud script is. emo
0
Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hier heb je hem met switch, ik heb hem niet getest en ik weet ook niet of het correct is.
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*
 * @author: Sebastiaan H
 * @product: Steen, papier, schaar
 */[/COLOR]
 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er gaat iets fout![/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/rand"]rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/switch"]switch[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700])
        {
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, het is dus gelijk spel.[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            default[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];
    }
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>

<form action="#" method="post">
    <select name="keuze">
        <option value="steen">Steen</option>
        <option value="papier">Papier</option>
        <option value="schaar">Schaar</option>
    </select>
    
    <input type="submit" value="Gok" />
</form>

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
0
Sebastiaanh

Lid · Topicstarter

Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Mooie errors Sander. yummie
0
Berichten
5.795
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sanderc schreef:
Hier heb je hem met switch, ik heb hem niet getest en ik weet ook niet of het correct is.
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*
 * @author: Sebastiaan H
 * @product: Steen, papier, schaar
 */[/COLOR]
 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er gaat iets fout![/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/rand"]rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/switch"]switch[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700])
        {
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, het is dus gelijk spel.[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            default[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];
    }
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>

<form action="#" method="post">
    <select name="keuze">
        <option value="steen">Steen</option>
        <option value="papier">Papier</option>
        <option value="schaar">Schaar</option>
    </select>
    
    <input type="submit" value="Gok" />
</form>

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
nu zit je wel switch te gebruiken maar heeft in jouw code nog geen zin.
dan kun je net zo goed if, else en elseif gebruiken
0
Berichten
1.871
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Bedankt had ik net nodig!
0
Berichten
551
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Lol door jou ben ik nu bezig met een steen papier schaar site alleen ben ik niet goed in php en ik wil een systeem maken met punten en login dat je kan gokken zegmaar (zonder geld) maar wel dat je punten kan winnen en punten kan inzetten,
Wil iemand helpen?
0
Berichten
397
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
ja boris wij zouden ook een website maken 1 dag doe je iets en daarna laat je niks meer van je horen......
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Sanderc schreef:
Hier heb je hem met switch, ik heb hem niet getest en ik weet ook niet of het correct is.
Spoiler tonen
[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #FF8000]/*
 * @author: Sebastiaan H
 * @product: Steen, papier, schaar
 */[/COLOR]
 
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_SERVER[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]REQUEST_METHOD[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]POST[/COLOR][COLOR= #007700])
{[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR][URL="http://www.php.net/isset"]isset[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]]))
    {[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]Er gaat iets fout![/COLOR][COLOR= #007700];
    }[/COLOR]
    [URL="http://www.php.net/else"]else[/URL]
    [COLOR= #007700]{[/COLOR]
        [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/rand"]rand[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]1[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]3[/COLOR][COLOR= #007700]);[/COLOR]
        
        [URL="http://www.php.net/switch"]switch[/URL][COLOR= #007700]([/COLOR]true[COLOR= #007700])
        {
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, het is dus gelijk spel.[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, het is dus gelijk spel[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
                
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt verloren![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]steen[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]3[/COLOR] [COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>schaar</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            case[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]papier[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]1[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>steen</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
            
            default[/COLOR] [COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]keuze[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]schaar[/COLOR] [COLOR= #007700]&&[/COLOR] [COLOR= #0000BB]$computer[/COLOR] [COLOR= #007700]==[/COLOR] [COLOR= #DD0000]2[/COLOR][COLOR= #007700]:[/COLOR]
                [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]De computer had <b>papier</b>, dus je hebt gewonnen![/COLOR][COLOR= #007700];
    }
}[/COLOR]
[URL="http://www.php.net/else"]else[/URL]
[COLOR= #007700]{[/COLOR]
?>

<form action="#" method="post">
    <select name="keuze">
        <option value="steen">Steen</option>
        <option value="papier">Papier</option>
        <option value="schaar">Schaar</option>
    </select>
    
    <input type="submit" value="Gok" />
</form>

[COLOR= #0000BB]<?php[/COLOR]
[COLOR= #007700]}[/COLOR]
?>
Google eens: php - switch
0
Berichten
551
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Brandon schreef:
ja boris wij zouden ook een website maken 1 dag doe je iets en daarna laat je niks meer van je horen......
Jij bent degene die er niks aan deed en jij laat ook niks van je horen...
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren