search
Homephp教程php手册实例研究PHP函数isset和empty的区别

实例研究PHP函数isset()和empty()的区别

  1  php error_reporting(E_ALL);
  2  echo   ' 未定义$var
' ;
  3  echo   " isset测试:
" ;
  4  if  ( isset ( $var ))
  5 {
  6      echo   ' 变量$var存在!
'  ;
  7 }
  8 
  9 
 10  echo   " empty测试:
" ;
 11  if  ( empty ( $var )){
 12      echo   ' 变量$var的值为空
' ;
 13 }
 14  else
 15 {
 16      echo   ' 变量$var的值不为空
' ;
 17 }
 18 
 19  echo   " 变量直接测试:
" ;
 20  if  ( $var ){
 21      echo   ' 变量$var存在!
' ;
 22 }
 23  else {
 24      echo   ' 变量$var不存在!
' ;
 25 }
 26 
 27  echo   ' ----------------------------------
' ;
 28  echo   ' $var = \ ' \ '
' ;
 29  echo   " isset测试:
" ;
 30  $var   =   '' ;
 31  if  ( isset ( $var ))
 32 {
 33      echo   ' 变量$var存在!
'  ;
 34 }
 35 
 36 
 37  echo   " empty测试:
" ;
 38  if  ( empty ( $var )){
 39      echo   ' 变量$var的值为空
' ;
 40 }
 41  else
 42 {
 43      echo   ' 变量$var的值不为空
' ;
 44 }
 45 
 46  echo   " 变量直接测试:
" ;
 47  if  ( $var ){
 48      echo   ' 变量$var存在!
' ;
 49 }
 50  else {
 51      echo   ' 变量$var不存在!
' ;
 52 }
 53  echo   ' ----------------------------------
' ;
 54  echo   ' $var = 0
' ;
 55  echo   ' isset测试:
' ;
 56  $var   =   0 ;
 57  if  ( isset ( $var ))
 58 {
 59      echo   ' 变量$var存在!
'  ;
 60 }
 61 
 62 
 63  echo   " empty测试:
" ;
 64  if  ( empty ( $var )){
 65      echo   ' 变量$var的值为空
' ;
 66 }
 67  else
 68 {
 69      echo   ' 变量$var的值不为空
' ;
 70 }
 71 
 72  echo   " 变量直接测试:
" ;
 73  if  ( $var ){
 74      echo   ' 变量$var存在!
' ;
 75 }
 76  else {
 77      echo   ' 变量$var不存在!
' ;
 78 }
 79  echo   ' ----------------------------------
' ;
 80 
 81  echo   ' $var = null
' ;
 82  echo   ' isset测试:
' ;
 83  $var   =   null ;
 84  if  ( isset ( $var ))
 85 {
 86      echo   ' 变量$var存在!
'  ;
 87 }
 88 
 89 
 90  echo   " empty测试:
" ;
 91  if  ( empty ( $var )){
 92      echo   ' 变量$var的值为空
' ;
 93 }
 94  else
 95 {
 96      echo   ' 变量$var的值不为空
' ;
 97 }
 98 
 99  echo   " 变量直接测试:
" ;
100  if  ( $var ){
101      echo   ' 变量$var存在!
' ;
102 }
103  else {
104      echo   ' 变量$var不存在!
' ;
105 }
106  echo   ' ----------------------------------
' ;
107 
108 
109  echo   ' $var = "php"
' ;
110  echo   ' isset测试:
' ;
111  $var   =   " php " ;
112  if  ( isset ( $var ))
113 {
114      echo   ' 变量$var存在!
'  ;
115 }
116 
117 
118  echo   " empty测试:
" ;
119  if  ( empty ( $var )){
120      echo   ' 变量$var的值为空
' ;
121 }
122  else
123 {
124      echo   ' 变量$var的值不为空
' ;
125 }
126 
127  echo   " 变量直接测试:
" ;
128  if  ( $var ){
129      echo   ' 变量$var存在!
' ;
130 }
131  else {
132      echo   ' 变量$var不存在!
' ;
133



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool