PHP supports 8 basic data types.
Four scalar types:
boolean (Boolean): This is the simplest type, with only two values, which can be TRUE/true or FALSE/false, case-insensitive. For details, please see: PHPBoolean type (boolean)
integer (integer): Its valid range in 32-bit operating systems is: -2 147 483 648~+2 147 483 647. Integer values can be expressed in decimal, hexadecimal or octal notation, and may be preceded by an optional sign (- or +). Octal represents a number that must be preceded by 0 (zero), and hexadecimal represents a number that must be preceded by 0x. For details, please see: PHPInteger data(Integer)
float (floating point type, also called double): the valid range in 32-bit operating systems is: 1.7E-308~1.7E +308. For details, please see: PHPFloating point type(float)
string (string): Character variables are different from otherprogramming languagesThere are characters and strings, in PHP , character variables are uniformly used to define characters or strings. For details, please see: PHP stringType (string)
Two composite types:
array (array): Array type variable is a special variable type that will be used in Details are provided in subsequent chapters.
object (object): Object is also a special data type. To create an object variable, use the new keyword. For details, please see: PHP object type (object)
Finally, there are two special types:
resource (resource): The source is a special variable that saves a reference to an external resource. Resources are created and used through specialized functions. For details, please see: PHP resource type (resource)
NULL (NULL): Indicates that a variable has no value. The only possible value of type NULL is NULL.
This article mainly introduces the method of PHP to view the current variable type. Friends who need it can refer to
PHP below The background, process and solution for viewing the current variable type have been written and sorted out for everyone. The details are as follows:
Solution background
Process one:
The json_decode of json in PHP has been solved and does not work without any output
In the meantime, you need to understand one thing:
PHP: curl_exe
What is the type of the variable $respJson returned by curl_exec? Is it string type?
Process 2:
1. Search:
php check variable type
Reference:
PHP: gettype – Manual
PHP: is_string – Manual
PHP: is_int – Manual
So try:
$respJson = $crifanLib->getUrlRespHtml($getTokenUrl); $crifanLib->logWrite("respJson=%s", $respJson); echo gettype($respJson); echo is_string($respJson); echo "before decodedJsonObj"; $decodedJsonObj = json_decode($respJson);
Result:
Still no output. . .
2. Try:
echo gettype($respJson); echo is_string($respJson);
Result:
Output: string1
## That proves that the type of the variable here is indeed string.
Summary
The variable type obtained in PHP is gettype($var);To determine whether it is a certain type alone, you can use:is_int is_string
The above is the detailed content of PHP summary of methods to view the current variable type. For more information, please follow other related articles on the PHP Chinese website!