面试官问:php的isset()用来干吗的,你怎么用?
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">面试中面试官问你啥问题,<span style="color: black;">博主</span>都给你整理在<span style="color: black;">这儿</span>了。<span style="color: black;">每日</span>都会整理一份最接地气的面试题,<span style="color: black;">期盼</span>能<span style="color: black;">帮忙</span>到你!</span></strong><strong style="color: blue;"><img src="https://mmbiz.qpic.cn/mmbiz_png/FZ0PKica3VFiczF4jrJnSn3MSXVGklE8rAJHUarDIYIwOTO8Q80XdAZCkQibz1wdeJywZ59GobIlrCgcKVNDrPqicg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_png/FZ0PKica3VF9Wbby3f3NnO5A4IkXSicovqmP1rmYGhmfXNoiawicUGia5Ph88Z0aamgEkibVss4MrLOygVXsbiaibS8QMw/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;"></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">同期</span>带上一套视频教程【</span><span style="color: black;"><strong style="color: blue;"><span style="color: black;">带你横扫PHP职场 全面<span style="color: black;">诠释</span>PHP面试</span></strong></span><span style="color: black;">】,感谢你对本公众号的关注<img src="https://mmbiz.qpic.cn/mmbiz_png/FZ0PKica3VFiczF4jrJnSn3MSXVGklE8rAnMqOIMlHWtbIYpicoV3rXHhQjQOkNI0fF0N6eOm5jGSPQYN3jIOZZxQ/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">,<strong style="color: blue;">关注本公众号</strong>,回复:</span><span style="color: black;"><strong style="color: blue;">160705</strong></span><span style="color: black;"><span style="color: black;"> <span style="color: black;">就可</span>获取。</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;">学习与交流:</strong><span style="color: black;"><strong style="color: blue;">PHP面试分享与交流群</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在<span style="color: black;">平常</span><span style="color: black;">研发</span>中经常会遇到<span style="color: black;">运用</span>isset()函数检测一个变量<span style="color: black;">是不是</span>设置,有什么需要<span style="color: black;">重视</span>的<span style="color: black;">地区</span>,今天<span style="color: black;">一块</span>来讨论一下。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">先上代码:</span></p>$arr[<span style="color: black;">a</span>] = <span style="color: black;">NULL</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>$arr[<span style="color: black;">b</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">] = ;</p>$arr[<span style="color: black;">c</span>] = <span style="color: black;">0</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>$arr[<span style="color: black;">d</span>] = <span style="color: black;">0.0</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>$arr[<span style="color: black;">e</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">] = [];</p>var_dump(<span style="color: black;">isset</span>($arr[<span style="color: black;">a</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>var_dump(<span style="color: black;">isset</span>($arr[<span style="color: black;">b</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>var_dump(<span style="color: black;">isset</span>($arr[<span style="color: black;">c</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>var_dump(<span style="color: black;">isset</span>($arr[<span style="color: black;">d</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>var_dump(<span style="color: black;">isset</span>($arr[<span style="color: black;">e</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运行结果是:</span></p><span style="color: black;">bool</span>(<span style="color: black;">false</span>) <span style="color: black;">bool</span>(<span style="color: black;">true</span>) <span style="color: black;">bool</span>(<span style="color: black;">true</span>) <span style="color: black;">bool</span>(<span style="color: black;">true</span>) <span style="color: black;">bool</span>(<span style="color: black;">true</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">这儿</span>的坑<span style="color: black;">或</span>疑问是:</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">isset就是检测一个变量<span style="color: black;">是不是</span>设置,<span style="color: black;">那样</span>设置成NULL<span style="color: black;">亦</span>叫设置,为啥返回false呢?</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span>对isset有疑问,那说明对手册圣经还是<span style="color: black;">无</span>看透。上手册:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">定义:isset — 检测变量<span style="color: black;">是不是</span>设置</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">用法:bool isset ( mixed $var [, mixed $... ] )</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">检测变量<span style="color: black;">是不是</span>设置,并且不是 NULL。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">倘若</span> var 存在并且值不是 NULL 则返回 TRUE,否则返回 FALSE。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">其实,NULL的含义<span style="color: black;">便是</span><span style="color: black;">无</span>值的意思,<span style="color: black;">亦</span><span style="color: black;">便是</span><span style="color: black;">无</span>设置值,var_dump(isset($arr));当然返回为false了。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">防坑扩展</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">1 看代码:</span></p>$b = <span style="color: black;">abcd</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>var_dump(<span style="color: black;">isset</span>($b[<span style="color: black;">0</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>var_dump(<span style="color: black;">isset</span>($b[<span style="color: black;">0</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">]));</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">结果是:</span></p><span style="color: black;">bool</span>(<span style="color: black;">true</span>) <span style="color: black;">bool</span>(<span style="color: black;">true</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">)</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">这个和python的字符串有些像,在<span style="color: black;">运用</span>isset时需要<span style="color: black;">重视</span>一下。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">2.<span style="color: black;">倘若</span>非得想判断$arr的值<span style="color: black;">是不是</span>为NULL怎么办呢?<span style="color: black;">能够</span><span style="color: black;">运用</span> array_key_exists()做判断。</span></p>$arr[<span style="color: black;">a</span>] = <span style="color: black;">NULL</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p><span style="color: black;">if</span>(array_key_exists(<span style="color: black;">a</span>, $arr) && $arr[<span style="color: black;">a</span>]===<span style="color: black;">NULL</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">){</p> <span style="color: black;">echo</span> <span style="color: black;">值是NULL</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">}</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">3.NULL不区分<span style="color: black;">体积</span>写,其含义是</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">NULL 值<span style="color: black;">暗示</span>一个变量<span style="color: black;">无</span>值。NULL 类型<span style="color: black;">独一</span>可能的值<span style="color: black;">便是</span> NULL。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">在下列<span style="color: black;">状况</span>下一个变量被认为是 NULL:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">- 被赋值为 NULL。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">- 尚未被赋值。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">- 被 unset()。</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">下面这道题你会选什么? 不妨留言</p>
<span style="color: black;"><span style="color: black;"><?php</span>$a = <span style="color: black;">123b</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>$b = <span style="color: black;">12a</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">;</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">var_dump($a<$b);</p>
</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">请问这段代码的运行结果是:</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">A、bool(true)</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">B、bool(false)</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;"><span style="color: black;">文案</span>来自:https://www.cnblogs.com/phpfensi/p/8143355.html</span></strong></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">以上是本文的<span style="color: black;">所有</span>内容,<span style="color: black;">期盼</span>对<span style="color: black;">大众</span>的学习有<span style="color: black;">帮忙</span>,觉得有用,有需要就支持一下吧</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><strong style="color: blue;">助你面试成功 拿下高薪岗位</strong></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">微X</span>公众号:<span style="color: black;">PHP面试题</span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">长按二维码关注</p><img src="https://mmbiz.qpic.cn/mmbiz_jpg/FZ0PKica3VF8AjdAlib9cfcsRE2ET0nOO6zxqicQrtIFZ3TODTdZVzRS8jSE17WMsDMt5ZaicRSWtPlD9cIGlgOIcQ/640?wx_fmt=jpeg&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" style="width: 50%; margin-bottom: 20px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">学习 | 交流 | 分享 | <span style="color: black;">文案</span></span> </p>
请问、你好、求解、谁知道等。
页:
[1]