Introduction
हेलो दोस्तों आज हम इस post tutorial में php के unset() function के बारेमे जानेगे. जब बी हमारी script मेसे किसी variable को destroy करना हो तो हम php का इस unset() function का इस्तेमाल से destroy कर सकते है!. तो इस unset function के बारे में आगे example के साथ जानेगे!.
unset() function syntax
php unset() function variable को unset करता है!.
Syntax:
unset(variable, ....);
variable name वह unset function के लिए जरुरी parameter है और उसके बाद के parameter optional होते है!.
php unset() function example
Example:
<?php
$ab = "Welcome RjtechyG";
echo "Before unset: " . $ab . "<br>";
unset($a);
echo "After unset: " . $ab;
?>
ऊपर के example में देख सकते है की हमने $ab name के variable में “Welcome RjtechyG” string value को assign की है उसके बाद में इस string को display की है echo का इस्तेमाल से और उसके बाद में हमने php unset() function से इस $ab varible को unset किया मतलब की destroy कर दिया है. variable को destroy करने के बाद में हम इस variable को echo करवाएंगे तो वह Undefined variable की error दिखायेगा!.
Example:
<?php
$variable ='Hello Dev';
function unset_variable()
{
global $variable;
echo "Before unset function : ".$variable."\n";
unset($GLOBALS['variable']);
}
echo "Outside function before using function : ".$variable."\n";
unset_variable();
echo "Outside function after using function : ".$variable."\n";
?>
ऊपर के example में देख सकते है की हमें $varaible नाम के एक global variable declared किया है उस variable में “Hello Dev” string को assing की है और इस variable को हम function के अंदर और function बहार कही बी उस कर सकते है!. तो हमने unset_variable() function call किया है और इस function के अंदर हमने इस global variable को unset यानि destroy कर दिया है!. और destroy होने के बाद में इस variable को access करने की कोसिस करते है तो वह हमें Undefined variable की error show करेनेगा!.