<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4572,"date":"2022-08-04T05:46:18","date_gmt":"2022-08-04T05:46:18","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4572"},"modified":"2022-08-04T05:46:18","modified_gmt":"2022-08-04T05:46:18","slug":"what-does-the-unlink-function-and-unset-function-mean","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/","title":{"rendered":"What does the unlink () function and unset () function mean ?"},"content":{"rendered":"<ul>\n<li style=\"text-align: justify;\">The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.<\/li>\n<\/ul>\n<h2 id=\"unlink-function\" style=\"text-align: justify;\">unlink () function<\/h2>\n<ul style=\"text-align: justify;\">\n<li>In PHP unlink () function is used when you want to delete the files completely and it is an inbuilt function.<\/li>\n<li>In this the filename of the file which has to be deleted is sent as a parameter and True on success and False on failure when the function returns.<\/li>\n<li>The unlink () function accepts two parameters in PHP they are filename and context.<\/li>\n<li>The filename is a mandatory parameter which specifies the filename of the file which has to be deleted.<\/li>\n<li>The context is an optional parameter which specifies the context of the file handle which can be used to modify the nature of the stream.<\/li>\n<li>Suppose there is a file named\u00a0<strong>\u2018gfg.txt\u2019, <\/strong>it returns True on success and False on failure.<\/li>\n<\/ul>\n<h2 id=\"sample-code\" style=\"text-align: justify;\">Sample Code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">&lt;?php<br\/> <br\/>\/\/ PHP program to delete a file named gfg.txt<br\/>\/\/ using unlink() function<br\/> <br\/>$file_pointer = fopen(&#039;gfg.txt&#039;);<br\/> <br\/>\/\/ Writing on a file named gfg.txt<br\/>fwrite($file_pointer, &#039;A computer science portal for Wikitechy!&#039;);<br\/>fclose($file_pointer);<br\/> <br\/>\/\/ Using unlink() function to delete a file<br\/>unlink(&#039;gfg.txt&#039;);<br\/> <br\/>?&gt;<\/code><\/pre> <\/div>\n<h2 id=\"output\" style=\"text-align: justify;\">Output<\/h2>\n<p style=\"text-align: justify;\"><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-4573\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png\" alt=\"\" width=\"1041\" height=\"169\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png 1041w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function-300x49.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function-1024x166.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function-768x125.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function-390x63.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function-820x133.png 820w\" sizes=\"(max-width: 1041px) 100vw, 1041px\" \/><\/p>\n<h2 id=\"unset-function\" style=\"text-align: justify;\">unset () function<\/h2>\n<ul style=\"text-align: justify;\">\n<li>The unset () function is used when you want to make that file empty and it is an inbuilt function which is used to remove the content from the file by emptying it in PHP.<\/li>\n<li>Thereby making it empty, the unset () function not only clears the file content but also is used to unset a variable.<\/li>\n<li>It means that the function clears the content of a file rather deleting it.<\/li>\n<li>This function accepts single parameter\u00a0<strong>variable <\/strong>which is required and it does not return any value.<\/li>\n<\/ul>\n<h2 id=\"sample-code-2\" style=\"text-align: justify;\">Sample Code<\/h2>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-php code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-php code-embed-code\">&lt;?php<br\/>      <br\/>$var = &quot;hello&quot;;<br\/>         <br\/>\/\/ Change would be reflected outside the function <br\/>function unset_value() {<br\/>    unset($GLOBALS[&#039;var&#039;]);<br\/>}<br\/>         <br\/>unset_value();<br\/>echo $var;<br\/>?&gt;<\/code><\/pre> <\/div>\n<h2 id=\"output-2\" style=\"text-align: justify;\">Output<\/h2>\n<p style=\"text-align: justify;\"><img decoding=\"async\" class=\"alignnone size-full wp-image-4574\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function.png\" alt=\"\" width=\"1037\" height=\"187\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function.png 1037w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function-300x54.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function-1024x185.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function-768x138.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function-390x70.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unset-function-820x148.png 820w\" sizes=\"(max-width: 1037px) 100vw, 1037px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently. unlink () function In PHP unlink () function is used when you want to delete the files completely and it is an inbuilt function. In this the filename of the file which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[8182],"tags":[17760,17765,17763,17766,17767,17761,17762,17764],"class_list":["post-4572","post","type-post","status-publish","format-standard","hentry","category-php","tag-difference-between-unlink-and-unset-in-php","tag-php-unlink-file-if-exists","tag-php-unlink-not-working","tag-unlink-image-in-php","tag-unlink-in-php-with-path","tag-what-is-unlink-in-php","tag-what-is-use-of-header-function","tag-what-is-use-of-header-function-in-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What does the unlink () function and unset () function mean ?<\/title>\n<meta name=\"description\" content=\"What does the unlink () function and unset () function mean ? - The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What does the unlink () function and unset () function mean ?\" \/>\n<meta property=\"og:description\" content=\"What does the unlink () function and unset () function mean ? - The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-04T05:46:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/\",\"name\":\"What does the unlink () function and unset () function mean ?\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png\",\"datePublished\":\"2022-08-04T05:46:18+00:00\",\"dateModified\":\"2022-08-04T05:46:18+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What does the unlink () function and unset () function mean ? - The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png\",\"width\":1041,\"height\":169},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What does the unlink () function and unset () function mean ?","description":"What does the unlink () function and unset () function mean ? - The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/","og_locale":"en_US","og_type":"article","og_title":"What does the unlink () function and unset () function mean ?","og_description":"What does the unlink () function and unset () function mean ? - The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/","og_site_name":"Wikitechy","article_published_time":"2022-08-04T05:46:18+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/","name":"What does the unlink () function and unset () function mean ?","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png","datePublished":"2022-08-04T05:46:18+00:00","dateModified":"2022-08-04T05:46:18+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What does the unlink () function and unset () function mean ? - The unlink () and unset () functions are used to do some undo operations but used in different situations because both acts differently.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/php\/what-does-the-unlink-function-and-unset-function-mean\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/unlink-function.png","width":1041,"height":169},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4572"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4572\/revisions"}],"predecessor-version":[{"id":4575,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4572\/revisions\/4575"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}