PHP unset() Function

What is unset() function in PHP?

Explanation

unset() function is used to destroy a variable. In the case of global variable, it destroys only the value of the variable, which is assigned inside the current function. The variable retains the previous value.

Syntax:


unset(var_name)

Example :


<?php
$val1='Hscripts.com';
echo 'Before using unset() the value of $val1 is : '. $val1.'<br>';
unset($val1);
echo 'After using unset() the value of $val1 is : '. $val1;
?>

Result :

Before using unset() the value of $val1 is : Hscripts.com
After using unset() the value of $val1 is :

Use PHP unset function for unsetting all variables.

PHP Topics


Ask Questions

Ask Question