PHP to view the current variable type, php to view the current variable
The following describes the background, process, and solution for PHP to view the current variable type. The details are as follows:
Background
Tossing process 1:
Solved json json_decode in PHP and no output
During this period, you need to understand one:
Copy codeThe Code is as follows:
PHP: curl_exec-Manual
The variable $ respJson returned by curl_exec is of the string type.
Tossing process 2:
1. Search:
Copy codeThe Code is as follows:
Php check variable type
Refer:
PHP: gettype-Manual
PHP: is_string-Manual
PHP: is_int-Manual
So try:
Copy codeThe 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 codeThe Code is as follows:
Echo gettype ($ respJson );
Echo is_string ($ respJson );
Result:
Copy codeThe Code is as follows:
Output: string1
It proves that the type of the variable here is indeed string.
Summary
The variable type obtained in PHP is gettype ($ var );
It is determined to be of a specific type. You can use:
Copy codeThe Code is as follows:
Is_int
Is_string
And so on.
The above is the method for viewing the current variable type in PHP. I hope you will like it.