26May/100
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.