PHP unset() Function

PHP unset() Function

The unset() function in PHP is used to unset a given variable. This function destroys the specified variables.

If this function is called inside any user-defined function, then it unsets the value associated with the variables inside it and leaves the value which is initialized outside it.

Syntax

unset ( mixed $var [, mixed $... ] ) 

Parameter

var(required)- This parameter represents the variable to unset.

Return

NA

Example 1

 

Output

Before the unset() function: Hello World
After the unset() function:  

Example 2

 

Output

The variable: TutorialAndExamples
After the unset() function...
The variable: TutorialAndExamples  

Example 3

 

Output

The variable: TutorialAndExamples
After the unset() function...
The variable:  

Related Topics

PHP sizeof() Function

PHP sizeof() Function The sizeof() function in counts all elements and return the size of the array. This function is an alias of count(). Syntax sizeof( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )  Parameter array_or_countable(required)– This parameter represents the input array or countable object. mode(optional)-...

1 minute read.

PHP array_shift() Function

PHP array_shift() Function The array_shift() in PHP shifts the first value of the array off. This function returns the same value after shortening the array by one element and moving everything. Syntax array_shift ( array &$array )  Parameter array(required)- This parameter represents the input array Return This function returns...

1 minute read.

PHP sort() Function

PHP sort() Function The sort() function in PHP sorts an array where the elements will be arranged from lowest to highest. Syntax sort ( array &$array [, int $sort_flags = SORT_REGULAR ] )  Parameter array(required)- This parameter represents the input array. sort_flags (optional)- This parameter is used to modify the...

1 minute read.

PHP join() Function

PHP join() Function The join() function of PHP returns a string from the elements of an array. This function is an alias of the implode() function. Syntax join(separator,array) Parameter separator(Optional)- Specifies what to put between the array elements. The default...

1 minute read.

PHP str_pad() Function

PHP str_pad() Function The str_pad() function in PHP pads a string to the given length with another string. Syntax str_pad ( string $input , int $pad_length [, string $pad_string  [, int $pad_type ]] ) Parameter input(required)- This parameter signifies the input string. pad_length(required)- This parameter specifies the length of the new string. If this value...

2 minutes read.

PHP pos() Function

PHP pos() Function The pos() function in PHP returns the current element in an array which is initialized to the first element of the array. This function is an alias of current(). Syntax pos ( array...

1 minute read.

PHP addslashes() Function

PHP addslashes() Function The addslashed() function in PHP is used to return a string with backslashes in front of predefined characters. This function is only used with some characters which are...

1 minute read.

PHP stripcslashes() Function

PHP stripcslashes() Function The stripcslashes() function in PHP returns a string with backslashes(\n, \r ..., octal and hexadecimal representation) stripped off. Syntax stripcslashes ( string $str )  Parameter str(required)- This parameter signifies the string to be unescaped. Return This function returns the unescaped string with backslashes stripped off. Example 1   ...

1 minute read.

PHP sha1_file() Function

PHP sha1_file() Function The sha1_file() in PHP calculates the sha1 hash of a file and returns the hash (40-character hexadecimal number). Syntax sha1_file ( string $filename [, bool $raw_output] )  Parameter filename(required)- This parameter represents the filename of the file to hash. raw_output(optional)- This...

1 minute read.

PHP array_reverse() Function

PHP array_reverse() Function The array_reverse() function in PHP returns a new array with the elements in the reversed order. Syntax array_reverse (array $array [, bool $preserve_keys = FALSE ] ) Parameter array(required)- This parameter represents the input array preserve_keys (optional)- This parameter specifies if the function should preserve the keys...

1 minute read.

PHP array() function

PHP array() function The array() function in PHP is used to create an array. Syntax array ([ mixed $... ] ) Parameter …(optional)- This parameter represents the elements’ values along with keys of the array. The syntax of this is as follows: "index => values"...

1 minute read.

PHP array_chunk() Function

PHP array_chunk() Function The array_chunk() function in PHP is used to split an array into chunks where the last chunk may contain less than size elements. Syntax array_chunk ( array $array , int $size [, bool $preserve_keys ]...

1 minute read.

PHP uasort() Function

PHP uasort() Function The uasort() function in PHP sorts an array with a user-defined comparison function and maintains the index association. Syntax uasort ( array &$array , callable $value_compare_func ) Parameter array(required)- This parameter represents the input array. value_compare_func(required)- This parameter represents a string that describe a...

1 minute read.

PHP array_key_exists() function

The array_key_exists () function in PHP is used to check whether the specified key exists in the array or not. It returns a Boolean value TRUE if the given key exists else it returns FALSE. Syntax array_key_exists(mixed key,array$array) Parameter key(required)- This...

1 minute read.

PHP Associative Arrays

PHP associate array is used to access the elements with keys by “=>” symbol. There are two ways to create an associative array. 1st way: $age = array("John"=>"20", "Helena"=>"30", "Rasmus"=>"29"); 2nd way: $age['john'] = "20"; $age['Helena'] =...

1 minute read.

PHP array_key_last() function

The array_key_last () function in PHP gets the last key of an array if the specified array is not empty. Syntax array_key_last ( array $array )  Parameter array(required)- This parameter signifies the input array. Return This function returns the last key of the...

1 minute read.

PHP strcmp() Function

PHP strcmp() Function The strcmp() function in PHP compares two strings. It is a binary-safe case-sensitive string function. This function is similar to the strncmp() function, with the difference that you can specify the number of characters from each...

1 minute read.

PHP bin2hex() Function | Convert Binary to Hexadecimal

PHP bin2hex() Function The bin2hex() function in PHP converts the specified string value of ASCII characters to hexadecimal value. Syntax bin2hex(str) Parameter str(Required): This parameter represents the string to be converted into hexadecimal. Return  This function returns...

1 minute read.

PHP array_fill() function

PHP array_fill() function The array_fill() function in PHP fills an user-defined array with num entries of the value that of specified values parameter, where the keys start at the start_index parameter. Syntax array_fill ( int $start_index , int $num , mixed $value ) Parameter start_index(required)- This parameter represents the first index of the...

1 minute read.

PHP array_udiff() Function

PHP array_udiff() Function The array_udiff() function in PHP calculates the difference of arrays by using a callback function for data comparison. Syntax array_udiff ( array $array1 , array $array2 [, array $... ], callable $value_compare_func ) Parameter array1(required)- This array represents the first input array. array2(required)- This array represents the second input array. array3….(optional)- It...

1 minute read.