PHP Learning notes-all equals

Source: Internet
Author: User

1. All equals not only the value of the variable is the same, but the same type is required. The following example

<? PHP $a=10; $b= ' ten '; Var_dump ($a= =$b,$a= = =$b);? >

The output is bool (TRUE) bool (false), which shows the difference between = = and = = =.

2. For an all-equal example, see the following code

 <? php   $str  = ' Hyper ' ;   $s  = ' h ' ;  if  (strpos  ( $str ,  $s ) ==false     $s . ' does not exist in '.  $str . ' ";}  else  { $ s . ' exist in '.  $str . ' ";} ? 

      The output is (H does not exist in hyper), which is strange, H is clearly in the hyper, but the output is not. Careful observation, found that H is the first letter of hyper, so the output of the Strpos () function is 0,0 and false = = operation, the result 0 is cast to Boolean false, of course, to prevent this situation, we use = = =, so not only the comparison value, but also the comparison type, There will be no mistakes. After correction, the following

<? PHP $str= ' Hyper '; $s= ' h '; if (strpos($str,$s) = = =false) {    echo$s. ' does not exist in '. $str. ' ';} Else {    echo$s. ' exist in '. $str. ' ';}? >

The output is (H exists in hyper).

PHP Learning notes-all equals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.