"Sacs" <alan_nospam_@way.co.nz> wrote in message
news:3Odce.2081$Od6.321012@news.xtra.co.nz...[color=blue]
> Ewoud Dronkert wrote:[color=green]
> > Sacs wrote:
> >[color=darkred]
> >>Variable variables:
> >>
http://www.php.net/manual/en/languag...s.variable.php[/color]
> >
> >
> > Yes. But why......:
> >[/color]
>
> Variable variables are one of the most powerfull features of php I've
> found. Very usefull when you dont know how many variables to be
> processed in a form for e.g.
>
> for( $i=1; $i <= $num_fields; $i++) {
> $blah = "field_" . $i;
> // $blah is now "field_1" first time through the loop
>
> $blah = $$blah;
> // now $blah holds what was input into the appropriate input
> }
>
> echo '<form>
> <input type=text name="field_1">
> <input type=text name="field_2">
> <input type=text name="field_3">
> <input type=hidden name="num_fields" value=3>
> <input type=submit>
> </form>';
>
>[color=green]
> >[color=darkred]
> >>$fooboo = "$a" . "$b";[/color]
> >
> >
> > Just do: $fooboo = $a . $b;
> >[/color]
> With just $fooboo = $a . $b; then $fooboo is set to "foobar" not "blah
> blah" as op wanted.
>
> Sacs[/color]
or even funkier ->
for( $i=1; $i <= $num_fields; $i++) {
${blah_$i} = $_REQUEST["field_$i"];
// variable creation on the fly...
// now $blah_1 - $blah_n holds what was input into the appropriate
input
echo "${blah_$i} \n\r";
}
echo '<form>
<input type=text name="field_1">
<input type=text name="field_2">
<input type=text name="field_3">
<input type=hidden name="num_fields" value=3>
<input type=submit>
</form>';
Norm
--
FREE Avatar hosting at
www.easyavatar.com