I have never understood these two functions very well. I will write a small program to deepen my understanding!
<?<span>php </span><span>/*</span><span>* * isset — 检测变量是否设置 * 如果 变量 存在则返回 true, 否则返回 false * * empty — 检查一个变量是否为空 * 如果 变量 是非空或非零的值,则 empty() 返回 false *</span><span>*/</span><span>$is_var</span> = ''<span>; </span><span>if</span>(<span>isset</span>(<span>$is_var</span><span>)) { </span><span>echo</span> "变量存在!<br />"<span>; } </span><span>else</span><span> { </span><span>echo</span> "变量不存在!<br />"<span>; } </span><span>if</span>(<span>empty</span>(<span>$is_var</span><span>)) { </span><span>echo</span> "变量为空!<br />"<span>; } </span><span>else</span><span> { </span><span>echo</span> "变量不为空!<br />"<span>; } </span>?>
Output result:
The variable exists!
The variable is empty!
The above has introduced the difference between empty and isset, including the content of empty. I hope it will be helpful to friends who are interested in PHP tutorials.