In-depth understanding of 0,null,empty, NULL, FALSE, and string relationships in PHP

Source: Internet
Author: User
  1. Determine the relationship between 0 and ' ' and empty null false start//

  2. if (' safdasefasefasf ' ==0) {

  3. echo "The string is converted to a number equal to 0
    ";
  4. }//output: The string is converted to a number equal to zero.

  5. This is one of the key examples

  6. This is explained in the manual: This value is determined by the first part of the string. If the string starts with a valid numeric data, the number is used as its value, otherwise its value is 0 (0).

  7. Which means ' 3asfdf ' ==3; ' Adsfasdf ' ==0 quite to notice

  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 ($a)) {
  19. echo "is empty
    ";
  20. }//output: ' Is empty
  21. if (Is_null ($a)) {
  22. echo "0 is null
    ";
  23. }//no Output
  24. if (Is_numeric ($a)) {
  25. echo "0 is numeric
    ";
  26. }//output:0 is numeric
  27. if (is_string ($a)) {
  28. echo "0 is string
    ";
  29. }//no Output
  30. if (strval ($a) = = ") {
  31. echo "0 is" converted into a string
    ";
  32. }//no Output
  33. Determine the relationship between 0 and ' ' and empty null false end//

  34. Determine 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. Judgment ' and 0 and empty null false ' relationship end//

  46. echo "In judging the Empty (") must be careful, 0 is equivalent to ", 0 and" are equivalent to null characters and false, the best to judge the empty = = = ";

  47. ?>

Copy Code

Output: 0 equals "" is the empty 0 is numeric "equals 0" or false 0 is false in judging the empty (") must be careful, 0 is equivalent to", 0 and "are equivalent to null characters and false, the best to determine the empty = = = Only this Sample interpretation: 0 is also equivalent to ", 0 and" are equivalent to null characters and false. When judging the empty (") must be careful, 0 is equivalent to", 0 and "are equivalent to null characters and false, the best to judge the empty = = =;

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.