检查,如果变量是数字或阵列 [英] Check if variable is a number or array

查看:146
本文介绍了检查,如果变量是数字或阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要检查,如果一个变量的内容是数字或数组。 is_array() is_int() is_numeric()来没有真正发挥作用。目前我使用myArray的[1],它似乎工作。但我不知道为什么这个功能的一个不能为我做到这一点?

编辑:

看来,我有这样的事情 myArray的['身份证'] 的内容,这始终是一个数组。


解决方案

  $阵列= is_array(13)? 是:无;
$ INT = is_int(13)? 是:无;
$数值= is_numeric(13)? 是:无;回声$阵列\\ n,$ INT\\ n,$数字\\ n。;

与回复

 


正如预期的那样,所以我真的不知道这个问题是在这里的!

这也许值得指出的是,如果你运行:

  $阵列= is_array(13)? 是:无;
$ INT = is_int(13)? 是:无;
$数字= is_numeric(13)? 是:无;回声$阵列\\ n,$ INT\\ n,$数字\\ n。;

的反应是:

 
没有

这又是如你所期望 - 字符串和一些没有被重新psented为数组$ P $

运行的GetType是这样的:

 回声的GetType(13);

显示它是一个整数

I want to check if the content of a variable is an number or array. is_array(), is_int(), is_numeric() don't really work. Currently I'm using myArray[1] which seems to work. But I'm wondering why one of this function cannot do this for me?

Edit:

It seems that I had something like myArray['id'] as content and this always is an array.

解决方案

$array = is_array(13) ? "yes" : "no";
$int = is_int(13) ? "yes" : "no";
$numeric = is_numeric(13) ? "yes" : "no";

echo $array."\n", $int."\n", $numeric."\n";

Replies with

no
yes
yes

As expected, so I'm not really sure what the issue is here!

It's perhaps worth noting that if you run:

$array = is_array("13") ? "yes" : "no";
$int = is_int("13") ? "yes" : "no";
$numeric = is_numeric("13") ? "yes" : "no";

echo $array."\n", $int."\n", $numeric."\n";

The response is:

no
no
yes

Which again is as you'd expect - a string and a number aren't represented as arrays.

Running gettype like this:

echo gettype(13);

shows it is an integer.

这篇关于检查,如果变量是数字或阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆