在PHP函数中传递可选参数 [英] Passing an optional parameter in PHP Function

查看:96
本文介绍了在PHP函数中传递可选参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将可选参数传递给PHP函数.例如

How can I pass an optional parameter to a PHP function. For example

function test($required, $optional){..}

这样我应该可以通过传递一个参数或传递两个参数来调用该函数.例如:

So that i should be able to call the function by passing either one parameter or both. For example:

test($required, $optional)
test($required);

谢谢.

推荐答案

尝试一下:

function test($required, $optional = NULL){..} 

然后您可以致电

test($required, $optional)

$optional为空

test($required);  

这篇关于在PHP函数中传递可选参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆