Common types of PHP detection functions. Unlike other languages, PHP is not a strict type language. Basically, this means that developers do not have to explicitly set the type of a variable before using it (numbers and characters are different from other languages. PHP is not a strict type language. Basically, this means that developers do not have to explicitly set the type (numbers, strings, and Boolean values) of a variable before using it ). Instead, the PHP interpreter automatically detects the type of the variable based on the information stored in the variable.
Although this feature is very easy to program using PHP, it also has an important drawback: when you need to test the type of a variable, the language with loose processing types is confusing. Fortunately, PHP developers noticed this situation and therefore included a function toolkit, especially used to test variables and find out which specific character classes they belong to-that is, whether they contain strings, integers, objects, or Boolean values.
The following lists the useful functions in this category and provides instructions and application instances.
Empty ($ var)
This function is used to check whether the variable is null (no value or zero value ). Use this function to check user input, such as table variables. Ensure that they contain valid data.
Gettype ($ var)
This function returns the type of the variable. For example, "string", "integer", "boolean", and "floating point value. Before inserting a variable into a strictly typed database domain, this function is generally used to verify whether the variable is the expected type.
Is_bool ($ var)
This function tests a variable to see if it contains a Boolean value (true/false ). Use this function to check whether the variable is a Boolean variable.
Is_string ($ var)
This function tests whether a variable is a string variable. Use this function to check whether a variable contains string data.
Is_numeric ($ var)
This function tests a variable to see if it contains a numeric or numeric string (a string includes a symbol, number, and decimal point ). Before using a variable for calculation, use this function to verify whether it contains a number.
Is_array ($ var)
This function tests a variable to see whether it is a PHP-related or numerical ordered index array. Before processing in a loop, use this function to check whether the variable is an array.
Is_null ($ var)
This function tests a variable to see if it is NULL. When evaluating the data returned by an SQL query, use this function to check whether a variable is NULL.
Is_object ($ var)
This function tests a variable to see if it is a PHP object. Before calling a method or access attribute, this function is generally used to test whether the variable is a PHP object.
Isset ($ var)
This function tests a variable to see if it has been defined. When evaluating the results of table submission, this function is generally used to test whether a variable is defined.
Print_r ($ var)
This function prints the content of a variable. This function is used to "snoop" a variable, especially when debugging a script.
Bytes. Basically, this means that before using a variable, developers do not have to explicitly set the variable type (numbers, characters...