{"id":8702,"date":"2020-04-27T11:00:59","date_gmt":"2020-04-27T02:00:59","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=8702"},"modified":"2020-04-24T19:16:44","modified_gmt":"2020-04-24T10:16:44","slug":"isset-vs-empty-in-php","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/8702","title":{"rendered":"Isset VS Empty In PHP"},"content":{"rendered":"\n<p>Today I will walk through the difference between isset &amp; empty , build in functions in PHP. <\/p>\n\n\n\n<h3>Iseet<\/h3>\n\n\n\n<p>It checks the variable to see if it has been set, in other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a &#8221; &#8220;, 0, &#8220;0&#8221;, or FALSE are set, and therefore are TRUE for ISSET.<\/p>\n\n\n\n<h3>Empty<\/h3>\n\n\n\n<p>It checks to see if a variable is empty. Empty is interpreted as: &#8221; &#8221; (an empty string), 0 (0 as an integer), 0.0 (0 as a float), &#8220;0&#8221; (0 as a string), NULL, FALSE, array() (an empty array), and &#8220;$var;&#8221; (a variable declared, but without a value in a class.)<\/p>\n\n\n\n<p>Lets do some comparisons.<\/p>\n\n\n\n<h4>Non declared variable<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>isset($novar) \u2013 Return FALSE\nempty($novar) \u2013 Return TRUE<\/code><\/pre>\n\n\n\n<h4>Null Variable<br><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$null = NULL; \nisset ($null) - Return FALSE \nempty ($null) - Return TRUE<\/code><\/pre>\n\n\n\n<h4>Empty String<br><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$emptyString = \"\"; \nisset($emptyString) - Return TRUE \nempty($emptyString) - Return TRUE <\/code><\/pre>\n\n\n\n<p><em><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\">This will be the same result for zero case.<\/font><\/font><\/em><\/p>\n\n\n\n<h4>Boolean value<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$tbl = TRUE; \n$fbl = FALSE; <\/code><\/pre>\n\n\n\n<p><em><strong><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\">Isset<\/font><\/font><\/strong><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\"> . Will Return TRUE For Both Cases <\/font><\/font><\/em><br><strong><font style=\"vertical-align: inherit\"><font style=\"vertical-align: inherit\">Empty<\/font><\/font><\/strong><br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>empty($tbl) - Return FALSE \nempty($fbl) - Return TRUE<\/code><\/pre>\n\n\n\n<h4>Empty Array<\/h4>\n\n\n\n<p>$arr = [];<br>The result will be true for both <strong>isset<\/strong> and <strong>empty<\/strong><\/p>\n\n\n\n<h4>Empty object <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>$obj = new stdClass (); \nisset ($obj) \u2013 return TRUE \nempty ($obj) \u2013 return FALSE<\/code><\/pre>\n\n\n\n<p><strong><em>Note: <\/em><\/strong>Isset only accepts single variable within its parenthesis. Passing others will proceed to error. For example<br>isset(strtoupper($var)) &#8211; this will proceed to error.<\/p>\n\n\n\n<p>By Yuuma<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8702\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/8702\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Isset VS Empty In PHP\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8702\" data-text=\"Isset VS Empty In PHP\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8702\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/8702\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Today I will walk through the difference between isset &amp; empty , build in functions in PHP. Iseet It check [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8702"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=8702"}],"version-history":[{"count":4,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8702\/revisions"}],"predecessor-version":[{"id":8709,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/8702\/revisions\/8709"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=8702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=8702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=8702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}