关于php的0,'',false,null引发的空字符串和空格的空字符串的思考

关于php的0,空字符串,false,null引发的空字符串和空格的空字符串的思考,今天在业务开发中遇到一个有点意思的问题,在仔细思考下发现了很有意思的点,接下来出题

  1. <?php
  2. $a = "";
  3. $b = " ";
  4. $c=trim($b);
  5. if($a==$b){
  6. var_dump('===');
  7. }else{
  8. var_dump("!=");
  9. }
  10. echo '<br>';
  11. if($a==$c){
  12. var_dump('===');
  13. }else{
  14. var_dump("!=");
  15. }
  16. ?>

以上为实例,不知道大家在初次遇到这个问题会怎么处理,是否会先入为主,而导致你业务出错,浪费宝贵时间。
以下为输出结果
eg:

  1. string(2) "!="
  2. string(3) "==="

我在没有仔细考虑这个问题的时候,一直认为,””、” “的区别,在肉眼上看,这个2个好像都是空字符串,可代码会告诉你,不,他们不一样,但是一定等你仔细看的时候,你一定就会发现,其中一个是因为多了一个空格,而在计算机的时间里,空格也是占用内存空间的,自然在语言处理中,也会进行区别对待。

所以任何事情都不能想当然,眼见不一定为实,一定要多思考,和实践。以下引用一下伟大领袖毛主席的话。

实践才是检验真理的唯一标准—-毛泽东

点赞 ( 0 )

20 条评论

  1. AmssmDwenueKes

    ivermectin 0.5% lotion ivermectin lotion for scabies

  2. wisit web site takip

    I was suggested this website by my cousin. I'm not sure whether this post is written by him as no one else know such detailed about my problem. You're wonderful! Thanks!

  3. Zack

    Good post. I certainly appreciate this site. Keep it up!

  4. I’m not that much of a online reader to be honest but your sites really nice, keep it up! I'll go ahead and bookmark your website to come back down the road. Cheers

  5. Konya Eczane Sigortası

    Fantastic beat ! I wish to apprentice while you amend your website, how can i subscribe for a blog web site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear idea

  6. Domingo

    Actually when someone doesn't know after that its up to other people that they will help, so here it happens.

  7. Bocaidama

    Magnificent beat ! I wish to apprentice while you amend your site, how could i subscribe for a weblog website? The account aided me a appropriate deal. I have been a little bit familiar of this your broadcast provided vibrant clear concept

  8. Adsmister

    Good answer back in return of this issue with genuine arguments and describing all about that.

  9. teknoloji haberleri

    Great article, totally what I was looking for.

  10. elektroniksigara

    I would like to thank you for the efforts you have put in penning this blog. I really hope to see the same high-grade content from you in the future as well. In fact, your creative writing abilities has motivated me to get my own website now ;)

  11. free followers

    I am regular visitor, how are you everybody? This piece of writing posted at this website is genuinely fastidious.

  12. instagram takipci satin alma

    Hey there! Do you know if they make any plugins to assist with Search Engine Optimization? I'm trying to get my blog to rank for some targeted keywords but I'm not seeing very good success. If you know of any please share. Thanks!

  13. instagram takipci

    If you desire to increase your knowledge simply keep visiting this web page and be updated with the most recent information posted here.

  14. youtube abone

    Thanks for every other informative website. The place else may I get that type of information written in such an ideal method? I've a project that I am simply now working on, and I have been at the look out for such information.

  15. youtube izlenme

    I constantly spent my half an hour to read this weblog's posts every day along with a cup of coffee.

  16. Wso php download

    Wow, amazing blog format! How long have you ever been blogging for? you make running a blog glance easy. The overall look of your website is great, let alone the content!

  17. more about the author

    Игры – новости и статьи по тегу more about the author

  18. wso shell download

    Someone necessarily assist to make severely articles I might state. That is the very first time I frequented your website page and thus far? I amazed with the research you made to make this particular post extraordinary. Wonderful job!

  19. instagram takipçi satın al

    Hey are using Wordpress for your site platform? I'm new to the blog world but I'm trying to get started and set up my own. Do you require any coding knowledge to make your own blog? Any help would be greatly appreciated!

  20. instagram takipçi arttirma türk

    Wow that was unusual. I just wrote an really long comment but after I clicked submit my comment didn't appear. Grrrr... well I'm not writing all that over again. Anyways, just wanted to say great blog!

发表评论

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

插入图片
s
返回顶部