dyn. Variablenname
Andreas
- php
Hallo,
ich habe im Form 4 Felder, gast1 bis gast4.
diese frage ich so ab:
For ($i=1; $i<=4; $i++){
if (isset($gast+$i)){
...
Dass das so nicht funktioniert ist klar, aber wie kann ich gast+i als Variable definieren?
Gruß Andreas
Moin!
For ($i=1; $i<=4; $i++){
if (isset($gast+$i)){
for($i=1; $i<=4; $i++){
$varname = "gast".$i;
if(isset($$varname)){
.....
}
}
tschüssi
ichen
Hallo,
$varname = "gast".$i;
if(isset($$varname)){
... oder ${'gast'.$i}
Gruß
Lachgas
Moin!
oder so. man könnte sich streiten, welche die bessere variante ist. meiner meinung nach ist es egal.
tschüssi
ichen
Hallo,
oder so. man könnte sich streiten, welche die bessere variante ist. meiner meinung nach ist es egal.
Das stimmt. Die zweite Methode hat nur den Vorteil, dass du nicht noch eine weitere Variable bestimmen musst. Aber ansonsten: "Jacke wie Hose" ;-)
Gruß
Lachgas
Hi,
... oder ${'gast'.$i}
... oder $GLOBALS["gast".$i], falls es sich nicht um eine lokale Variable handelt. ;-)
Gruß, Cybaer
Hallo,
hat super geklappt, danke.
Gruß Andreas