The difference between isset() and empty() in php is: isset() function is used to detect whether the variable is set, the syntax format is: [isset (mixed var)]; empty() function is used to determine the value Whether it is empty, the syntax format is: [empty(mixed var)].
isset() function
isset() function is generally used to detect whether a variable is set.
Format:
bool isset ( mixed var [, mixed var [, ...]] )
Return value:
If the variable does not exist, it returns FALSE;
If the variable exists and its value is NULL, it also returns FALSE ;
If the variable exists and the value is not NULL, TRUE is returned;
When multiple variables are checked at the same time, TRUE is returned only when each single item meets the previous requirement, otherwise the result is FALSE .
empty() function
empty() function is used to determine whether the value is empty.
Format:
bool empty ( mixed var )
Return value:
If the variable does not exist, it returns TRUE;
If the variable exists and its value is "", 0, "0", NULL,, FALSE, array(), var $var; and objects without any attributes, return TRUE;
If the variable exists and the value is not "", 0, "0", NULL, FALSE, array(), var $var; and objects without any attributes, return FALSE.
Example: Simple comparison of empty() and isset()
Note: empty() only detects variables, and detecting anything that is not a variable will cause a parsing error.
If you want to learn more related knowledge, please visitphp Chinese website.
The above is the detailed content of What is the difference between isset() and empty() in php. For more information, please follow other related articles on the PHP Chinese website!