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
Variable Variable?
Moderator: General Moderators
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];
?>-
alphaseinor
- Forum Newbie
- Posts: 2
- Joined: Fri Oct 24, 2003 5:56 am
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can do variable variables:
http://php.net/variables.variable
but arrays are generally easier to deal with.
Mac
http://php.net/variables.variable
but arrays are generally easier to deal with.
Mac