2017-01-15 7 views
0

PHPが新しくバージョン5.6を使用しています。私は間接参照を使用する場合のunset()の機能を理解しようとしています。 unset()は、以前の変数が使用していた空きメモリを、その値への他の変数参照がない場合に設定します。私のコードでunset()はうまく動作し、falseを返します。しかし、変数への間接参照を使用すると、それでもfalseが返されます。ここで は私のコードです...PHPで間接参照を使用してunset()の作業を理解できない

//unsetting the variable 
    $unset_var="darsh"; 
     //Indirect refernces to variables 
     $$unset_var="new to PHP"; 
     echo "\n\n".$darsh; 
    unset($unset_var); 
    if(isset($unset_var)) 
    { 
     print "<br>".'$unset_var variable is not free to use'; 
    } 
    else 
    { 
     print "<br>".'$unset_var variable is free to use'; 
    } 
+0

そして、何?間接参照はどこですか? –

答えて

0

多分これは役立ちます:

$a = "x"; 
$$a = 'Value of $$a'; // creates a variable called $x 
         // because the literal value of $a = 'x' 
         // think about it as: ${$a} 

echo $$a . "<br>"; // 'Value of $$a' 
echo $x . "<br>"; // 'Value of $$a' 

unset($a); 

echo $a . "<br>"; // Notice: Undefined variable 
echo $$a . "<br>"; // Notice: Undefined variable - because {$a} has been unset 
echo $x . "<br>"; // 'Value of $$a' - $x has not been unset 
関連する問題