Home >Backend Development >PHP Tutorial >PHP method to view the current variable type, PHP to view the current variable_PHP tutorial
The following is the background, process and solution of checking the current variable type in PHP. The details are As follows:
Resolve background
Tossing process one:
Solved json_decode of json in PHP not working without any output
During this period, you need to understand one thing:
Copy code The code is as follows:
PHP: curl_exec – Manual
What is the type of the variable $respJson returned by curl_exec? Is it a string type?
Tossing process two:
1. Search:
Copy code The code is as follows:
php check variable type
Reference:
PHP: gettype – Manual
PHP: is_string – Manual
PHP: is_int – Manual
So go try it:
Copy code The code is as follows:
$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:
Copy code The code is as follows:
echo gettype($respJson);
echo is_string($respJson);
Result:
Copy code The code is as follows:
Output: string1
That proves that the type of the variable here is indeed string.
Summary
Getting the variable type in PHP is gettype($var);
To individually determine whether it is a certain type, you can use:
Copy code The code is as follows:
is_int
is_string
Wait.
The above is the method for checking the current variable type in PHP. I hope you like it.