Home > Backend Development > PHP Tutorial > How to view the current variable type using PHP

How to view the current variable type using PHP

不言
Release: 2023-04-01 15:40:02
Original
8080 people have browsed it

This article mainly introduces the method of checking the current variable type in PHP. Friends who need it can refer to it.

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

Solution background

Tossing process one:

The json in PHP has been solved json_decode is not working and there is no output. During this period, you need to understand one thing:

PHP: curl_exec – Manual
Copy after login

curl_exec What is the type of the variable $respJson returned, and whether it is a string type.

Tossing process two:

1. Search:

php check variable type
Copy after login
Reference:

PHP: gettype – Manual

PHP: is_string – Manual

PHP: is_int – Manual

So try it:

$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:

echo gettype($respJson);
echo is_string($respJson);
Copy after login
Result:
输出:string1
Copy after login

This proves that the type of the variable here is indeed It's a 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
Copy after login

Wait.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Analysis of the implementation principles of scheduled tasks in PHP


Use PHP's scope analysis Operator(::)

The above is the detailed content of How to view the current variable type using 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