php - What is the best way to know is $_GET['example']=="somevalue"? -
if((isset($_get[example]))&&($_get['example']=='somevalue')){ ... } or
if((!empty($_get[example]))&&($_get['example']=='somevalue')){ ... } or just
if($_get['example']=='somevalue'){ ... } i asking why have seen many example people check first if $_get['example'] set , if $_get['example']=='somevalue' ( first , second example above ). don't understand why not use last solution ( if $_get['example']=='somevalue' $_get['example'] set ).
this question refers other variable ( $_post, $_server, ecc ).
if((isset($_get[example]))&&($_get['example']=='somevalue')){ ... } is right one, want know "variable" exists (or set) in order use it. empty checks wether has data of kind or not. example:
<?php $foo= 0; if (empty($foo)) { // true because $foo empty echo '$foo either 0, empty, or not set @ all'; } if (isset($foo)) { // true because $foo set echo '$foo set though empty'; } if (isset($var)) { // false because $var not declared before ... } ?>
Comments
Post a Comment