CopyPastehas never been so tasty!

Check variable is set or not using Isset() function in PHP

by anonymous

  • 0
  • 0
  • 0

Orignal Source:


Isset() Function:


Isset function is used in php to check whether a $variable holds a value or not. As its name describe it is used to check whether the variable is set or not. If the $variable hold a value it returns true or 1 otherwise it will return false or 0.


For example, in order to check whether the username and password are filled or not, we use isset function in php.





    $username = "Tahreem";


    if (isset(  $username )) {                                                       

            echo "username  is set<br/>";

    } else {

            echo "username  is not set<br/>";



    if (isset($password)) {

            echo "password is set<br/>";

    } else {

            echo "password is not set<br/>";







username is set
password is set


Explanation of the Example:

In the above Example we have checked that whether $username and $password have a value or not using isset function. If the $username has a value message will be printed username is set. It means it is not empty. Then we have checked the $password isset if it has a value then message will be printed password is set otherwise password is not set. 

Add A Comment: