[PHP] Goede script?

Gestart doorDylan9 reacties42 weergaven

10 berichten · pagina 1 van 1

Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]20[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]betaalscherm 20[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]50[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]betaalscherm 50[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]100[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]betaalscherm 100[/COLOR][COLOR= #007700];
}[/COLOR] 

[URL="http://www.php.net/elseif"]elseif[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]] ==[/COLOR] [COLOR= #DD0000]10[/COLOR][COLOR= #007700])
{[/COLOR]  
    [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]betaalscherm 10[/COLOR][COLOR= #007700];
    }[/COLOR] 
?>


is dit goed gescript? want volgens mij hoort er ook nog iets van iffset bij..
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/switch"]switch[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]]){

case[/COLOR] [COLOR= #0000BB]20[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 20"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];

case[/COLOR] [COLOR= #0000BB]50[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 50"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
case[/COLOR] [COLOR= #0000BB]100[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 100"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
case[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 10"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];

default:[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Geen betaalscherm"[/COLOR][COLOR= #007700];



}[/COLOR]

?>


Switch lijkt me t beste, iig beter dan zoveel elses yummie
0
Berichten
3.788
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het kan zo, maar je kan ook iets meer elseifs gebruiken, en daarnaast zou inderdaad een isset ook kunnen
0
Dylan

Lid · Topicstarter

Berichten
14.025
Reputatie
1
Punten
0,01
Lid sinds
Laatst gezien
Kyron schreef:
[COLOR= #0000BB]<?php[/COLOR]

[URL="http://www.php.net/switch"]switch[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]]){

case[/COLOR] [COLOR= #0000BB]20[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 20"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];

case[/COLOR] [COLOR= #0000BB]50[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 50"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
case[/COLOR] [COLOR= #0000BB]100[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 100"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
case[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 10"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];

default:[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Geen betaalscherm"[/COLOR][COLOR= #007700];



}[/COLOR]

?>
Switch lijkt me t beste, iig beter dan zoveel elses yummie
Werkt idd beter, bedankt.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
nog mooier:

[COLOR= #0000BB]<?php[/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]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]])) {[/COLOR]
 [URL="http://www.php.net/switch"]switch[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$_GET[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]aantal[/COLOR][COLOR= #007700]]){
 case[/COLOR] [COLOR= #0000BB]20[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 20"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
 case[/COLOR] [COLOR= #0000BB]50[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 50"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
 case[/COLOR] [COLOR= #0000BB]100[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 100"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];
 case[/COLOR] [COLOR= #0000BB]10[/COLOR][COLOR= #007700]:[/COLOR]   [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"betaalscherm 10"[/COLOR][COLOR= #007700];[/COLOR]
                [URL="http://www.php.net/break"]break[/URL][COLOR= #007700];

 default:[/COLOR] [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"Geen betaalscherm"[/COLOR][COLOR= #007700];
 }
}[/COLOR]
?>
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
@ aarclay: Volgens mij vangt de switch dat automatisch af met "default:", maar hier ben ik niet 100% zeker van.

Uiteraard is het wel netter om het zo te doen zoals bovenstaand voorbeeld.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Ik ben het in ieder geval zo gewend.

Enne, nee, default: vangt dat niet af:
http://3v4l.org/hlDMN
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
^ dan heb ik niks gezegd!
0
Berichten
3.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aarclay schreef:
Ik ben het in ieder geval zo gewend.

Enne, nee, default: vangt dat niet af:
http://3v4l.org/hlDMN
Oh, das eigenlijk logisch als ik t zo bekijk, als de $_GET false is switcht ie m niet yummie
edit: NVM, dan kun je natuurlijk gewoon

case false:  
case NULL:
echo "Geen betaalscherm";
                 break;
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
AH, de break; misste ik nog zag ik bloosMaar dat maakt niet uit... voor deze testcase, blijft toch hetzelfde, wat ik al verwachtte yummie
Need koffie....
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