PHP has several functions that can be used to test the state of a variable. The first function is isset (). It has the following function prototype: boolisset (mixedvar); [; mixedvar [,...]). This function requires a variable name as the parameter.
PHP has several functions that can be used to test the state of a variable. The first function is isset (). It has the following function prototype: bool isset (mixed var); [; mixed var [,...]), this function requires a variable name as a parameter. if the variable exists, true is returned; otherwise, false is returned. You can also pass a list of variables separated by commas. If all variables are set, the isset () function returns true. You can also use the unset () function corresponding to the isset () function to destroy a variable. It has the following function prototype:
Void unset (mixed var); [; mixed var [,...])
This function will destroy a passed variable. The empty () function can be used to check whether a variable exists and whether its value is non-null or non-zero. the corresponding return value is true or false. It has the following function prototype:
Bool empty (mixed var );
Now we can look at an example of using these three functions. Try to temporarily add the following code to a script:
Echo 'isset ($ username): '. isset ($ username ).'
';
Echo 'isset ($ nothere): '. isset ($ nothere ).'
';
Echo 'empty ($ username): '. empty ($ username ).'
';
Echo 'empty ($ nothere): '. empty ($ nothere ).'
';
Refresh the page to view the running results. No matter what value is entered in the form field or no value is input at all, the $ username variable in the isset () function returns 1 (true ). In the empty () function, the returned value depends on the value entered in the form field. $ Nothere variable does not exist. Therefore, a blank result (false) will be generated in the isset () function, and 1 (true) will be generated in the empty () function ).
These functions are very convenient to use, so that you can enter the form correctly.