Get the App
SLTechnology News&Howtos  ›  Development  › 

The usage of isset () and! empty () functions in PHP

Shulou Source: shulou.com Published: 2022-06-03 19:46:59 09月30日 Update

This article introduces the knowledge of "the usage of isset () and! empty () function in PHP". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The isset () function is a built-in function in PHP that checks whether the variable is set and is not NULL. This function also checks whether the declared variable, array, or array key has a null value, and if so, isset () returns false, which returns true in all other possible cases.

Syntax:

Bool isset ($var, mixed)

Parameters: this function accepts multiple parameters. The first argument to this function is $var. This parameter is used to store the value of the variable.

Example:

Output:

0 isset with isset functionarray is not set.

The empty () function is a language construct that determines whether a given variable is empty or NULL.! The empty () function is a negation or supplement to the empty () function. The empty () function and! The isset () function is equivalent, but! The empty () function equals the isset () function.

Example:

Output:

0 is considered empty1 is considered set

Check the reasons for the two functions:

Isset () and! The empty () function is similar, and both will return the same result. But the only difference is! The empty () function does not generate any warnings or electronic notifications when the variable does not exist. It is sufficient to use any function. Merging the two functions into the program can lead to the passage of time and unnecessary memory use.

Example:

Tags: Function variable parameter output array check two content function situation more knowledge practical same successful next memory reason dilemma multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno NVidia macOS Shulou Technology Huawei