Home > Backend Development > PHP Tutorial > PHP method to view the current variable type, PHP to view the current variable_PHP tutorial

PHP method to view the current variable type, PHP to view the current variable_PHP tutorial

WBOY
Release: 2016-07-13 09:45:21
Original
791 people have browsed it

How to check the current variable type in PHP, check the current variable in php

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1041335.htmlTechArticleHow to check the current variable type in PHP, check the current variable in PHP. Below is the background, process and process of checking the current variable type in PHP. The solutions have been written and sorted out for everyone, as follows:...
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