Solved

Variable Variables and $_POST

Posted on 2013-01-18
3
332 Views
Last Modified: 2013-01-18
I've got a multitude of strings on a site with a numerical suffix and am trying to use a loop (and later when working a function).
What I'm stuck on is the formatting to parse the variable text into $_POST so I can read the value from the previous page.
$VVBLE = "Number$LoopNumber";
$$VVBLE = $POST['$VVBLE'];

Open in new window

As highlighted above the $_POST['$VVBLE'] is what I'm stuck on, what formatting should I use for it to use that as the lookup value?
0
Comment
Question by:kiwistag
3 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 400 total points
Comment Utility
Is this what you want ?

<?php
error_reporting(E_ALL);

$_POST['Number1'] = 100;
$_POST['Number2'] = 200;
$_POST['Number3'] = 300;

for($i=1;$i<=3;$i++)
{
    $LoopNumber = $i;
    $VVBLE = "Number".$LoopNumber;
    $$VVBLE = $_POST[$VVBLE];
}

var_dump($Number1);
var_dump($Number2);
var_dump($Number3);

Open in new window

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
this should do it?
$$VVBLE = $POST[$VVBLE];
0
 
LVL 6

Author Closing Comment

by:kiwistag
Comment Utility
Thanks, the issue was actually (that I'd missed completely) that I'd put $POST and not $_POST. No idea why I kept overlooking it but your code was great for fault finding!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now