我有一个具有多个参数的函数,我想在我的代码中的几个地方调用它。如何使用一些默认值来调用它,例如:
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.
默认参数值