PHP unset() function29 Aug 2024 | 3 min read The unset() function is a predefined variable handling function of PHP, which is used to unset a specified variable. In other words, "the unset() function destroys the variables". The behavior of this function varies inside the user-defined function. If a global variable is unset inside a function, the unset() will destroy it locally and leave the same value initially provided for outside. Use the $GLOBALS array to destroy a global variable inside the function. Note: A variable will not be considered to be set for so long if it is unset using the unset() function.SyntaxMixed denotes that the parameter can be multiple types. ParametersThis function accepts one or more parameters, but atleast one parameter must be passed in this function. variable (required) - This parameter is mandatory to pass as it holds that variable, which is needed to be unset. … - More number of variables to be unset, which are optional to pass. Return ValuesNo value is returned by the unset() function. ExamplesBelow some examples are given through which you can understand the working of the unset() function: Example 1: Output: Before using unset() the domain name of website is : javatpoint.com Notice: Undefined variable: website in C:\xampp\htdocs\program\unset.php on line 5 After using unset() the domain name of website is : Example 2: Use of unset() In this example, we will use the unset() function to destroy the variable. Look at the below example: Output: Variable before unset : test bool(true) Notice: Undefined variable: var_value1 in C:\xampp\htdocs\program\unset.php on line 10 Variable after unset : bool(false) Example 3: Unset GLOBAL variable, but no changes reflect If you directly try to unset the global variable inside a function, the changes will be reflected locally, not globally. Output: Welcome to javatpoint. Example 4: Unset global variable when changes reflect Use the $GLOBAL array to unset a global variable inside a function. Output: Notice: Undefined variable: var_value1 in C:\xampp\htdocs\program\unset.php on line 11 Example 5: Destroy static variable Output: Value before unset: 1, Value after unset: 25 Value before unset: 2, Value after unset: 25 Value before unset: 3, Value after unset: 25 Next TopicGet and Post Methods in PHP |
You could occasionally be redirected to an empty form when using an online form after providing information and being instructed to go back and edit it! This irritates me greatly. A sticky form is one in which you are sent to a form that preserves...
7 min read
While working with PHP, many times the developer requires converting the array data into string so they can easily implement the String functions to the data. In this tutorial, we will briefly discover the various ways of converting Array into String in PHP. PHP provides different inbuilt...
3 min read
In this article, we will understand about a with the help of various examples. What do you mean by Ternary operator? It is also called a conditional operator. The ternary operator is an operator that decreases the length of code while performing comparisons. It is an alternative...
4 min read
It is possible to define anonymous functions in PHP. In PHP, a function is often defined by giving it a name that may be used to invoke the function whenever needed. Conversely, a function that lacks a name at the time of definition is known...
4 min read
PHP PHP print_r() is a built-in function that displays information about a variable in a human-readable way. It shows the information stored in a variable, which is easily understandable to the user. There are two more functions similar to print_r() which are var_export(), and var_dump(). They display...
2 min read
Imagearc( ) function is another inbuilt PHP function mainly used to draw an arc of a circle with a particular center and given coordinates. The function works using the x and y-axis, used to set coordinates for the starting point from where the picture has to...
7 min read
In this section, we are going to learn the rest API with passport authentication. We will use Laravel and PHP to do this. In our Laravel application, we will create rest API. We will also install and implement passports for authentication. In our application, we can...
11 min read
The division operation uses in the web application without mathematical operators and functionalities. PHP language has a built-in function called gmp_div_q() that is used for dividing the two figures. Here, we cannot use decimal numbers using a simple function, but it works on negative values also. Syntax The...
2 min read
In this article, we will learn about the use of dialog boxes of JavaScript i.e., the alert box, confirmation box, and prompt dialog box in PHP. In this, we will learn some basics of JavaScript, PHP, dialog boxes and its examples. What do you mean by JavaScript? JavaScript...
5 min read
PHP basename( ) Function PHP functions are a self-centric block of statements that can be executed a number of times as per the developer's requirements. PHP contains multiple inbuilt functions that can be used at times of need. In these functions, we don't have to give the definition...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India