A problem with variable variables in PHP.
$y = "_POST[\"131rde" . $x . "box\"]";
if ($$y == "yes"){DO SOME STUFF;}
Seems to be failing. Details below.
I have been taking in data from my site with this:
$rde1 = $_POST["131rde1box"];
$rde2 = $_POST["131rde2box"];
$rde3 = $_POST["131rde3box"];
$rde4 = $_POST["131rde4box"];
$rde5 = $_POST["131rde5box"];
$rde6 = $_POST["131rde6box"];
$rde7 = $_POST["131rde7box"];
$rde8 = $_POST["131rde8box"];
$rde9 = $_POST["131rde9box"];
Each post either contains nothing or the string "yes". I have many such inputs so I was trying to speed up like with variable variables.
for ($x = 1; $x <= count($rdeex); $x++) {
$y = "rde" . $x;
if ($$y == "yes"){array_push($chosenquestions,$rdeex[$x-1]);}
}
The above works absolutely fine.
I have tried to speed up to get rid of the horrible repeated lines at the top with:
for ($x = 1; $x <= count($rdeex); $x++) {
$y = "_POST[\"131rde" . $x . "box\"]";
if ($$y == "yes"){array_push($chosenquestions,$rdeex[$x-1]);}
}
But it fails. And I've no idea why. The string "_POST["131rde" . $x . "box"]" seems to be fine.
I'm something of a newbie and recognise that the above is pretty poor style, but wondering just why it fails at the moment. Thank you.