首頁  >  文章  >  後端開發  >  布林值 true/false 和字串 "true"/"false&

布林值 true/false 和字串 "true"/"false&

WBOY
WBOY原創
2016-07-25 09:11:181539瀏覽
Booleans are used to represent the concepts of true and false. They are most often used for testing if a statement is true or false and they'll play a bigger role when we discuss logical expressions.Note that there is a difference between boolean true/false and the strings "true"/"false".
  1. Booleans and NULL
  2. /* Booleans are used to represent the concepts of true and false.
  3. They are most often used for testing if a statement is true or false and
  4. they'll play a bigger role when we discuss logical expressions.
  5. Note that there is a difference between
  6. boolean true/false and the strings "true"/"false".
  7. */
  8. $bool1 = true;
  9. $bool2 = false;
  10. // When booleans are displayed, PHP will attempt to convert them into a string
  11. // You'll get either "1"/"0" or "1"/"" instead of true/false
  12. ?>
  13. $bool1:
  14. $bool2:

  15. /* NULL is used to represent the concept of nothing or the state of being empty
  16. In the below example three variable have been set,
  17. then boolean tests are performed and the results are output as a string
  18. */
  19. $var1 = 3;
  20. $var2 = "cat";
  21. $var4 = NULL;
  22. // isset tests whether a variable has been set
  23. // It returns true or false as a result of the test.
  24. ?>
  25. $var1 is set:
  26. $var2 is set:
  27. $var3 is set:
  28. $var1 is set:
  29. $var2 is set:
  30. $var3 is set:

  31. $var1 empty:
  32. $var4 empty:
复制代码


陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn