How to recall a variable variable in PHP?

Fred L

New member
Here is what I am doing. I am setting variable variables like this:


$ref_num = 5;
$num = 0;

while($num<$ref_num) {
$num++;
$to_name_ . $num = trim($_POST['to_name_$num']);
$to_email_ . $num = trim($_POST['to_email_$num']);
}


This works great, but the problem is, when I need to recall the variable I try to do so like this:


$ref_num = 5;
$num = 0;

while($num<$ref_num) {
$num++;
if($to_name_ . $num=="") {
echo "Ok";
}


PHP does not like the way I am recalling the variable, and it always comes up blank.

Any ideas how to do what I am trying to do?

The $num_ref is a dynamic, user entered number. And I am creating one text field for each num_ref. I then need to be able, dynamically to check each text field individually.
 
Back
Top