【发布时间】:2023-03-31 20:27:01
【问题描述】:
假设我有函数
public function test($dataid){
.........
}
现在我只想在$dataid 必须是数组时运行函数。如果不是,那就不行了
ifi 传递了一个字符串,例如 test("string") 它不会运行。
我知道is_array(),但还有其他解决方案吗?
如果 value 为空,它将自动转换为数组
【问题讨论】:
-
除了
is_array,你可以使用类型检查.. -
公共函数测试((array)$dataid){
-
我如何输入检查?
-
And if value is empty it will be automatically convert to array? -
如果值为空,为什么要将值转换为数组?