最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】PHP如何查看当前变量的类型

PHP crifan 2795浏览 0评论

【背景】

折腾:

【已解决】PHP中的json的json_decode不工作没有任何输出

期间,需要搞懂一个:

PHP: curl_exec – Manual

curl_exec 返回的变量$respJson的类型是什么,是不是string类型。

【折腾过程】

1.搜:

php check variable type

参考:

PHP: gettype – Manual

PHP: is_string – Manual

PHP: is_int – Manual

所以去试试:

$respJson = $crifanLib->getUrlRespHtml($getTokenUrl);
$crifanLib->logWrite("respJson=%s", $respJson);
echo gettype($respJson);
echo is_string($respJson);
echo "before decodedJsonObj";
$decodedJsonObj = json_decode($respJson);

结果:

还是没有任何输出。。。

2.试试:

echo gettype($respJson);
echo is_string($respJson);

结果:

输出:string1

那就证明,此处的变量的类型的确是string的。

 

【总结】

PHP中获得变量类型是gettype($var);

单独判断是某种类型,可以用:

is_int

is_string

等等。

转载请注明:在路上 » 【已解决】PHP如何查看当前变量的类型

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.168 seconds, using 22.03MB memory