PHP unset()

📔 : PHP 🔗

unset() , किसी variable को unset करता है। unset करने का मतलब है उस variable को NULL assign करता है , जिससे उस variable की value को आगे use न कर सकें।

PHP unset() Syntax
unset ( mixed $var , mixed ...$vars );
  1. mixed $var | required : variable जिसे आपको unset करना है। 

  2. mixed ...$vars | optional : आप एक साथ कई variables unset  कर सकते हैं। हालाँकि कम से काम एक variable mandatory होता है।

  3. Return Value : variable unset होने के बाद true return करता है , otherwise false .


Understanding mixed Type

mixed type का मतलब होता है , कि आप अपनी need के according किसी भी type (String , Boolean , Array , Class , Numeric) की value pass कर सकते हैं। यह जरूरी नहीं है कि कोई special type की value ही pass करें।

PHP unset Example

File : php_unset.php

Copy Fullscreen Close Fullscreen
<?php 
  $var = "Hello world!.";
  unset($var);
  var_dump($var);
?>
Output
NULL

हालाँकि unset() का use करके आप normal variable के अलावा Array / Object / Session भी unset कर सकते हैं।

  $arr = ['red' => 'aaple', 'yellow' => 'Banana', 'Green' => 'Guava'];
  print_r($arr);
  echo "After unset 'red' ";
  unset($arr['red']);
  print_r($arr);
  
  
Output :
Array ( [red] => aaple [yellow] => Banana [Green] => Guava ) After unset 'red' Array ( [yellow] => Banana [Green] => Guava )

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook