Q:

What does the ${$key} expression mean in "foreach" construction?

In my project I receive data from an html form into the _POST massive. Then I need to pass it into the _SESSION massive, and as far as I understand, I need to validate this received data to keep on working with it.
Trying to understand how to do this I found an exapmle of good-working code, but I don't understand it quite well. Please help me clarify what this code really means.
$arr = array(
    'a' => FILTER_SANITIZE_NUMBER_INT,
    'b' => FILTER_SANITIZE_NUMBER_INT,
    'c' => FILTER_SANITIZE_NUMBER_INT,
    'd' => FILTER_SANITIZE_NUMBER_INT,
        );

$arr1 = filter_input_array(INPUT_POST, $arr);

foreach ($all2 as $key => $value) {
    ${$key} = $value;
    $_SESSION[$key] = $value;
}

In fact the problem remains with
{
    ${$key} = $value;
    $_SESSION[$key] = $value;
}

I can't find what does the expression ${$key} mean.

A:

It creates variables based on the value of the key in the array.
So if $_POST['name'] exists, and you're looping through it, it creates a variable called $name and sets it equal to $value.
$_SESSION[$key] in the above example is also setting the name key in the SESSION array.
I find this practice to be useful, because instead of having to type <?php echo $_POST['name']; ?> you can use <?php echo $name; ?>.  However, it has its own risks, because if name isn't passed in the post, you're attempting to echo a variable that doesn't exist. 

