Evaluating Variable Status
While using php you will need to evaluate or test your variables using conditional statements or functions. Or by using functions in your conditional statements. there are a few functions that can assist us to determine whether our variables have a value assigned to them, or to check if they are empty or not. They are as follows:
- isset()
- empty()
- unset()
isset() Takes your variable as an argument and returns TRUE if it has a value or FALSE if it does not.
empty() Takes your variable as an argument and returns TRUE if it is empty or FALSE if it is not.
unset() Will allow you to take any set variable and obliterate it by removing its value and the variable from memory all together.
Remember: You can reverse the functions output by placing the ("!" NOT) operator in front of it.
<?php $myVar = "test"; IF !empty($myVar) //normally empty would return FALSE because we set or variable, the "!" reverses this to TRUE { echo "I am set"; //This will be returned }else{ echo "I am not set"; //This will NOT be returned } ?>