2016-02-26 66 views

回答

3

它允许您更改动态调用哪个变量。我在PHP中使用了这个功能,带有双美元符号$$。

$var = 'bar'; 
$bar = 'hello'; 
echo $$var; // Output is hello 

你可以考虑一下为$($ VAR),此时它首先对内部的表达,则评估外与内的结果。我曾经在用户输入的环境中使用过。

// In a controller 
for(array('email', 'firstname', 'lastname') as $input){ 
    $$input = $_POST[$input]; //Will create a variable with that name 
    sanitation_function($$input); //This will sanitate the input 
}