In-depth understanding of the relationship between 0, null, empty, null, false, and strings in php

Source: Internet
Author: User
In-depth understanding of the relationship between 0, null, empty, null, false, and strings in php

  1. // Judge the relationship between 0 and ''and empty null false. start //

  2. If ('safdasefasefasf' = 0 ){

  3. Echo "this string is converted to a number equal to 0
    ";
  4. } // Output: the string is converted to a value equal to zero.

  5. This is a key example.

  6. This value is determined by the first part of the string. If a string starts with a valid number, use this number as its value. Otherwise, its value is 0 (0 ).

  7. That is to say, '3asfdf '= 3; 'adsfasdf' = 0.

  8. $ A = 0;

  9. If ($ a = ''){
  10. Echo "0 equals''
    ";
  11. } // Output: 0 equals''
  12. If (trim ($ a) = ''){
  13. Echo "trim (0) equals''
    ";
  14. } // No output

  15. If ($ a = ''){

  16. Echo "0 =''
    ";
  17. } // No output
  18. If (empty ($ )){
  19. Echo "'' is empty
    ";
  20. } // Output: ''is empty
  21. If (is_null ($ )){
  22. Echo "0 is null
    ";
  23. } // No output
  24. If (is_numeric ($ )){
  25. Echo "0 is numeric
    ";
  26. } // Output: 0 is numeric
  27. If (is_string ($ )){
  28. Echo "0 is string
    ";
  29. } // No output
  30. If (strval ($ a) = ''){
  31. Echo "convert to string 0 is''
    ";
  32. } // No output
  33. // Determine the relationship between 0 and ''and empty null false. end //

  34. // Judge the relationship between ''and 0 and empty null false. start //

  35. $ B = '';

  36. If ($ B = 0 ){
  37. Echo "'' equals 0
    ";
  38. } // Output: ''equals 0
  39. If (! ''){
  40. Echo "'' is false.
    ";
  41. } // Output: ''is false.
  42. If (! 0 ){
  43. Echo "0 is false
    ";
  44. } // Output: 0 is false bbs.it-home.org
  45. // Determine the relationship between ''and 0 and empty null false. end //

  46. Echo "when judging null (''), be careful. 0 is equivalent to '', 0 and'', both are equivalent to null and false, it is best to use = ";

  47. ?>

Output result: 0 is equal to "" is empty 0 is numeric "is equal to 0". false 0 is false. be careful when determining null ("). 0 is equivalent ", both 0 and "are equivalent to null characters and false. it is best to use = to judge as null. it can only be interpreted as follows: 0 is also equivalent to", 0 and "are equivalent to null characters and false. Be careful when determining the null ("). 0 is equivalent to", 0 and "are equivalent to null characters and false. it is best to use = to judge the null;

Echo 0 = null; echo '**
'; // Trueecho 0 === null; echo '**
'; // Falseecho (string) 0! = Null; echo '**
'; // Trueecho 0! = Null; echo '**
'; // Falseecho 0! = Null; echo '**
'; // True

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.