Ben*_*son -3 php arrays parameters function
function request($suffix, array $post = array(), $action = NULL) {
// do something...
}
Run Code Online (Sandbox Code Playgroud)
我在书中看到了一个功能.但我不明白该关键字在函数的参数列表中的array含义$post.我觉得省略array遗嘱会产生同样的效果.
它是否充当数据类型提示符?如果是这样,那么为什么我不能用string,integer等先于其他参数?
function request($suffix, array $post = array(), $action = NULL) {
// do something...
}
Run Code Online (Sandbox Code Playgroud)
该函数接受多个参数,参数$ post是类型暗示为数组
array $post = array()
Run Code Online (Sandbox Code Playgroud)
在这里我们可以看到$ post被默认分配一个空数组,因此它符合它的类型
$post = array() and array $post = array() will return the same
Run Code Online (Sandbox Code Playgroud)
如果你尝试传递除了数组之外的其他东西作为该函数的参数,你将得到错误
类型提示是指更多解释