如何在 php 中使用整数值识别默认参数


How can I identify default parameters with integer value in php

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

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

那么user_idstatue当我们不传递它时会有默认值吗?

谢谢。

这是

正确的方法,通过分配$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.

默认参数值