Web Development Unites Design and Programming
Web design and Web Programming are united to create Web Development. Many beginning web designers never develop skills that include programming. However, it is imperative to gain knowledge of programming to introduce dynamic elements to your designs.
More to come...
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 } ?>
Functions for Variables
Variables need special attention. Especially when you are using the ===(identical too) comparison operator, which will ensure you have a stricter set of conditional statements. They are as follows:
- gettype() will return the a string containing the type name or "unknown" if it is not one of the following types (integer, double, string, array, or object)
- settype() will set a variable to a specific type that is specified. takes two arguments.. (variable, type)
- is_array() will return true or false dependant on whether the variable passed is an array
- is_double(), is_float(), is_real() (all equivalent) will return true or false dependant on whether the variable passed is an integer with a decimal or negative
- is_long(), is_int(), is_integer() (all equivalent) will return true or false dependant on whether the variable passed is an whole integer
- is_string() will return true or false dependant on whether the variable passed is an string
- is_object() will return true or false dependant on whether the variable passed is an object
These variable functions can be useful prior to working with a variable that needs to be of a specific type. This can ensure your programs do not crash.