Home  >  Article  >  Backend Development  >  The difference between empty and isset in php

The difference between empty and isset in php

WBOY
WBOYOriginal
2016-07-25 09:07:44783browse
  1. /**

  2. * isset — Check whether a variable is set
  3. * Return true if the variable exists, false otherwise
  4. *
  5. * empty — Check whether a variable is empty
  6. * If the variable is a non-empty or non-zero value, empty() returns false
  7. **/

  8. $is_var = '';

  9. if (isset($is_var)) {

  10. echo "The variable exists!
    ";
  11. } else {
  12. echo "The variable does not exist!
    ";
  13. }

  14. < ;p>if(empty($is_var)) {
  15. echo "The variable is empty!
    ";
  16. } else {
  17. echo "The variable is not empty!
    ";
  18. }
  19. ?>

Copy the code

Output results: The variable exists! The variable is empty!



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn