php 是变量数组或对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10957100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php is variable an array or object
提问by chris
Trying to figure out how to do the equivalent of something I did in javascript but in php. But I'm not sure of the operators to do it. In javascript I wanted to see if a particular parameter being passed was either an object or array.. and if not then was it a string/int and what I did was something like
试图弄清楚如何做相当于我在 javascript 但在 php 中所做的事情。但我不确定运营商会这样做。在javascript中,我想查看传递的特定参数是对象还是数组..如果不是,那么它是一个字符串/整数,我所做的就像
if (str instanceof Array || str instanceof Object)
{
//code
}
else
{
//code
}
anyone know of the equivalent to this for php?
任何人都知道这相当于 php 吗?
回答by Ry-
回答by WOLFF
Try to use:
尝试使用:
if (!is_scalar($var)) {
// Varible is object or array
}
回答by Yani
I came across this question while looking for is_countable. Maybe it's of some use to somebody.
https://www.php.net/manual/en/function.is-countable.php
我在寻找is_countable. 也许它对某人有用。
https://www.php.net/manual/en/function.is-countable.php
回答by Vishal Mohan
object (use is_object)-----
对象(使用 is_object)-----
stdClass Object
(
[rest_food_items_id] => 137
[rest_user_id] => 42
)
array (use is_array)----
数组(使用 is_array)----
Array
(
[rest_food_items_id] => 137
[rest_user_id] => 42
)
**
**
Example
例子
**
**
if(is_object($data)){
}
if(is_array($data)){
}

