Page 1 of 1

Variable Variable?

Posted: Fri Oct 24, 2003 5:56 am
by alphaseinor
Hello this is my first post,


Is it possible to do a variable variable?

Say I have variables:
$a1 = 1.01;
$a2 = 1.02;
$a3 = 1.04;
$total = 0.00;

and I am passing a variable from a form (using get) called:
$esc //which just happens to be 2

is it possible to do something like this:
echo $a$esc
$total = $total + $a$esc

Thanks,

Alphaseinor

Posted: Fri Oct 24, 2003 6:59 am
by richie256
you must do this way:

Code: Select all

<?php
$a[1] = 1.01;
$a[2] = 1.02;
$a[3] = 1.04;

$esc = $_GET['esc'];

echo $a[$esc];
$total = $total + $a[$esc];
?>

Posted: Fri Oct 24, 2003 7:24 am
by alphaseinor
Thanks

Forgot about arrays...

I think you need a raise 87)

Posted: Fri Oct 24, 2003 8:10 am
by twigletmac
You can do variable variables:
http://php.net/variables.variable
but arrays are generally easier to deal with.

Mac