Setting a variable to be the text of another variable.
Posted: Thu Aug 04, 2011 11:22 am
I am making a friends list which uses a loop, and it has a variable, $a, which goes up two each time. Is there a way that I could set a variable to be p followed by $a, such as:
$p2
$p4
$p6
I did think about $"p".$a but that did not work. Can anybody shed some light on this matter?
If you are wondering why I need this, it is to create a friends list where there will also be buttons which need to be able to link exclusively to the variables where there can be different amounts of variables.
$p2
$p4
$p6
I did think about $"p".$a but that did not work. Can anybody shed some light on this matter?
Code: Select all
<?php
echo <<<END
<input type="Submit" value = "Echo" name ="Submitter">
END;
$fr = "hello"; #Is a MySQL query, but as I am just wondering about the variables, it is not needed.
$len = strlen($fr);
$a = 0;
for ($i = 1; $i <= $len; $i++) {
$a = $a +2;
$"p".2 = $a #This is the line which should be able to update
}
$len2 = $len/2;
if (isset($_POST['Submitter'])) {
$p = 0;
for ($i = 1; $i <= $len2; $i++) {
$p = $p+2;
echo $"p".$p;
}
}
?>