Re: how to combine the results of two variables to echo another variable?



"Sacs" <alan_nospam_@xxxxxxxxx> wrote in message
news:3Odce.2081$Od6.321012@xxxxxxxxxxxxxxxxxx
> Ewoud Dronkert wrote:
> > Sacs wrote:
> >
> >>Variable variables:
> >>http://www.php.net/manual/en/language.variables.variable.php
> >
> >
> > Yes. But why......:
> >
>
> 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>';
>
>
> >
> >>$fooboo = "$a" . "$b";
> >
> >
> > Just do: $fooboo = $a . $b;
> >
> With just $fooboo = $a . $b; then $fooboo is set to "foobar" not "blah
> blah" as op wanted.
>
> Sacs

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


.