look at this simple script please
$c1 = $_GET[c1];
$c2 = $_GET[c2];
$c3 = $_GET[c3];
$c4 = $_GET[c4];
$c5 = $_GET[c5];
for($i = 1;$i <=5;$i++)
{
echo $c{$i};//or something else here :/
}
how can i print tha values of variables?
Thanks
look at this simple script please
$c1 = $_GET[c1];
$c2 = $_GET[c2];
$c3 = $_GET[c3];
$c4 = $_GET[c4];
$c5 = $_GET[c5];
for($i = 1;$i <=5;$i++)
{
echo $c{$i};//or something else here :/
}
how can i print tha values of variables?
Thanks
You can see on php.net some good examples in the variable page. Read that and take a look at the examples.
Also, below is your piece of code fixed so it can work:
<?php
$c1 = $_GET[c1];
$c2 = $_GET[c2];
$c3 = $_GET[c3];
$c4 = $_GET[c4];
$c5 = $_GET[c5];
for($i = 1;$i <=5;$i++)
{
echo ${"c".$i};
}
$c1, $c2 etc checks the $_GET contents. If he would have asked for other solutions, I would suggest others, but it seems to me this questions is about variable variables.You should use an array rather than individual variables.
For reference:
Here's a better way of doing it, using Arrays, rather than individual variables, which works easier and more efficiently.
<?php
$array['c1'] = $_GET['c1'];
$array['c2'] = $_GET['c2'];
$array['c3'] = $_GET['c3'];
$array['c4'] = $_GET['c4'];
$array['c5'] = $_GET['c5'];
for ($i=1; $i>=5; $i++) {
echo $array['c' . $i];
}
?>
Perhaps PHP variable variables is what you are looking for.
$i = "c1";
print $$i;
I'll leave it to you to figure out how to construct correct values for 'i'.