This works too? How can this problem be solved?

Source: Internet
Author: User
This works too? Is the string and 0 of all letters always equal? PHPcodeif (& quot; e & quot ;== 0) {echo & quot; Yes & quot ;;}# result: # Yes, & quot; e & quot; is it true if it is not a variable?
Is the string and 0 of all letters always equal? Explanations
PHP code
  if("e" == 0){    echo "Yes";}#result:#Yes


------ Solution --------------------
"E" is not a variable in the memory. nothing .......
------ Solution --------------------
This way:
PHP code
Echo "e" = 0;
------ Solution --------------------
Php will automatically convert the type of the variable, and convert string to int if int and string are compared. as a result, all strings are 0, and the result is determined, you can use = full to determine
------ Solution --------------------
This solution is clearer:

Echo intval ('e'); # The conversion fails. the default value is 0 (print: 0)
Echo intval ('1ds2e'); # if there is an integer in the string, convert it to int (print: 1) from the first position)

Discussion

This way: PHP code
Echo "e" = 0;

------ Solution --------------------

This statement is wrong. "If there is an integer in the string, convert it from the first position to int (print: 1 )"

It should be like this:

If an integer appears in a string and the integer is at the starting position of the string, it is taken out and converted to an int.

Discussion

This solution is clearer:

Echo intval ('e'); # The conversion fails. the default value is 0 (print: 0)
Echo intval ('1ds2e'); # if there is an integer in the string, convert it to int (print: 1) from the first position)

Reference:

This way: PHP code
Echo "e" = 0;

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.