在php7中,千万不要把你的??当成三元运算符使用!!!

  1. <?php
  2. $tmparr = ['cover'=>'http://img.kevinfei.com.cn'];
  3. echo isset($tmparr['cover'])."\n";
  4. echo !empty($tmparr['cover'])."\n";
  5. $rep = isset($tmparr['cover']) && !empty($tmparr['cover']) ? $tmparr['cover'] : '';
  6. var_dump($rep);
  7. $result = isset($tmparr['cover']) && !empty($tmparr['cover']) ?? '';
  8. var_dump($result);
  9. // 1
  10. // 1
  11. // string(24) "http://img.kevinfei.com.cn"
  12. // bool(true)
  13. ?>

php7新增一个运算符??,不知道大家平时是在什么时候用它,但是我一直用它代替以前的三元运算符? :,今天偶然发现,它和三元运算符是不一样的,.

在想用??判断一个赋值为0的变量的时候要小心了,结果可能和想象中的不一样

从上面的结果可以看出,在php7中 ?? 代表isset ?: 代表empty

今天想告诉大家在php7中关于这个几个最常用的内置函数而可能会引发的问题,需要注意一下啊!!!

点赞 ( 1 )

17 条评论

  1. Alba

    Hey There. I found your weblog the use of msn. This is an extremely smartly written article. I'll make sure to bookmark it and return to learn extra of your helpful information. Thanks for the post. I'll definitely comeback.

  2. bit.ly

    I am in fact happy to glance at this website posts which includes tons of useful information, thanks for providing these kinds of data.

  3. t.co

    Your style is so unique compared to other people I've read stuff from. Many thanks for posting when you have the opportunity, Guess I will just bookmark this blog.

  4. wisit takip site

    I believe that is one of the so much significant information for me. And i am glad reading your article. But should remark on few basic issues, The website taste is ideal, the articles is really nice : D. Just right task, cheers

  5. instagram takipçi al

    Right now it seems like Movable Type is the preferred blogging platform available right now. (from what I've read) Is that what you are using on your blog?

  6. Aylık beğeni satın al

    Fenomega ile instagram aylık beğeni satın almak ve tüm paylaşımlarınıza yada belirtilen sayıdaki paylaşımlarınız için özel https://cutt.ly/QSWJRyg aylık beğeni satın al

  7. Visit websiteizlenme

    This paragraph provides clear idea in support of the new viewers of blogging, that actually how to do blogging and site-building.

  8. visit webpage

    Wow, this paragraph is pleasant, my sister is analyzing such things, thus I am going to convey her.

  9. visitwebsite

    I don't even know how I finished up here, however I assumed this publish was great. I don't realize who you are but certainly you are going to a well-known blogger if you happen to aren't already. Cheers!

  10. visit website

    Excellent site. Plenty of helpful information here. I am sending it to several buddies ans additionally sharing in delicious. And of course, thank you in your effort!

  11. go website

    I am truly delighted to read this website posts which consists of plenty of useful data, thanks for providing these kinds of statistics.

  12. link-analysis

    I have read some excellent stuff here. Definitely value bookmarking for revisiting. I wonder how so much effort you put to make the sort of great informative web site.

  13. takip

    What's Taking place i'm new to this, I stumbled upon this I've discovered It absolutely helpful and it has helped me out loads. I hope to contribute & assist other users like its helped me. Great job.

  14. It's actually a great and useful piece of info. I'm satisfied that you simply shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

  15. BahisKrallığı

    İnternetteki bahis siteleri hakkındaki en önemli detaylardan biri de güvenlik özellikleridir. Güvenli bahis platformları hakkında bilgileri arayan kullanıcılar için BahisKrallığı sitemizdeki paylaşımlar öne çıkıyor.

  16. BahisDurağı

    BahisDurağı web sitesinde bahis tutkunları için en doğru kaynaklar yer alır. Bahis oyuncularına rehberlik eden sitede bahis opsiyonları, güncel bahis seçenekleri, maç analizlerinin yer aldığı siteler hakkında bilgiler mevcut.

  17. Konya Havacılık Sigortası

    Keep on working, great job!

发表评论

人生在世,错别字在所难免,无需纠正。

插入图片
s
返回顶部