我有一个多参数的函数,我想在我的代码中的几个地方调用它。如何使用以下默认值来调用它:
Addhistory($h_id, $h_name, $user_id=0, status=true)
所以当我们不通过时,user_id
和statue
会有默认值吗?
谢谢。
这是正确的方法,通过分配$user_id=0
和$status=true
你定义他们的默认值。
1.定义功能
function Addhistory($h_id, $h_name, $user_id=0, $status=true){
//do something with parameters
}
2.使用默认参数值调用函数。
Addhistory(1,'example_string')//you need to just pass $h_id and $h_name as arguments if you want to call the function with default argument values.