Detailed explanation of how to view the type instance of the current variable in PHP

伊谢尔伦
Release: 2023-03-12 06:22:02
Original
1332 people have browsed it

The following is the background, process and solution for viewing the current variable type in PHP. The details are as follows:

Solution background

Tossing process one:

The json_decode of json in PHP has been solved. There is no output during the work

, you need to understand one:

The code is as follows:

PHP: curl_exec – Manual
Copy after login

curl_exec returns What is the type of the variable $respJson? Is it the string type?

Tossing process two:

1. Search:

The code is as follows:

php check variable type
Copy after login

Reference:

PHP: gettype – Manual

PHP: is_string – Manual

PHP: is_int – Manual

So go try it:

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);
Copy after login

Result :

Still no output. . .

2. Try:

The code is as follows:

echo gettype($respJson);
echo is_string($respJson);
Copy after login

Result:

The code is as follows:

输出:string1
Copy after login

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:

The code is as follows:

is_int
is_string
Copy after login

and so on.

The above is the detailed content of Detailed explanation of how to view the type instance of the current variable in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template