0

Simple questions I hope but I just can't get the solution.

I have a foreach loop producing variable $checkbox.

I then have a field name, for the example approvereject

I want to create a new variable that combines the fieldname and the forecah value.

So:

$joinedvariable=approvereject.$checkbox

This does not work, I have also tried:

$joinedvariable=${approvereject_.$checkbox};

but when I echo $joinedvariable I simply get a blank result.

Lastly, I want to use $joinedvariable in a $_POST statement:

$_POST[$joinedvariable ] - will this work as I cant get it right?

1
  • 1
    Has nothing to do with variable variables. You just need a concated array key for $_POST ($_POST is an array variable, not a "statement", or "function"). Commented Feb 20, 2013 at 12:04

3 Answers 3

1

Try this :

$joinedvariable="approvereject".$checkbox;

$_POST[$joinedvariable];
Sign up to request clarification or add additional context in comments.

Comments

1
$joinedvariable='approvereject'.$checkbox

Comments

1

If you have some code like this:

foreach ($checkboxes as $checkbox) {
    echo '<input type="checkbox" name="approvereject_'. $checkbox .'" value="1">';
}

in a <form> with method="post", than you can try to get values of checkboxes like this:

foreach ($checkboxes as $checkbox) {
    print_r(!empty($_POST['approvereject_'. $checkbox]));
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.