如何在php中识别带整数值的默认参数

问题描述 投票:2回答:2

我有一个多参数的函数,我想在我的代码中的几个地方调用它。如何使用以下默认值来调用它:

Addhistory($h_id, $h_name, $user_id=0, status=true)

所以当我们不通过时,user_idstatue会有默认值吗?

谢谢。

php function default
2个回答
1
投票

这是正确的方法,通过分配$user_id=0$status=true你定义他们的默认值。


0
投票

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.

default argument values

© www.soinside.com 2019 - 2024. All rights reserved.