Why does looping a session array key in PHP not work compared to explicit declaration

Viewed 22

I am new to web development, I am trying an algorithm to loop a session array key in PHP instead of explicit/individual declaration and without the use of actual arrays as I noticed that session array key can be a variable value, here is an example of the code I am working on:

//this doesn't work
for($x=1;$x<4;$x++){
        echo "$x".$_REQUEST["'text".$x."'"];
}
//this works
echo "<br>1".$_REQUEST["text1"];
echo "<br>2".$_REQUEST["text2"];
echo "<br>3".$_REQUEST["text3"];

What could be the solution for this?

1 Answers

It's echo "<br>".$x.$_REQUEST["text".$x];

Btw $_REQUEST and $_SESSION are different beasts.

Related