调用PHP函数 [英] Call PHP function

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

问题描述

我有PHP 函数采用多参数。我想打电话给这个函数与设置仅最后一个参数。简单的办法是设置其他参数的的。但它是不好的。

时的任何方式来调用这个函数与最后一个参数设置,不设置其他的说法?

请参阅下面的例子:

 函数MyFunction的($ A,$ B,$ C,$ D,$ E,$ F)
{
    //// 做一点事
}////简单方法
MyFunction的(,,,,,值);////我的示例
MyFunction的(argument6:值)


解决方案

我的建议是使用数组,而不是使用参数的数量,例如你的函数调用应该是这样的。

  $ PARAMS [6] ='值';
MyFunction的($ params)方法;

有关确定第六个参数设置了

 函数MyFunction的($ params)方法{
 如果(使用isset($ PARAMS [6]))//参数Six于价值 }

我希望这将是一个替代方法。

I have php function by multi parameter. I want to call this function with setting only last argument. Simple way is setting other argument empty. But it isn't good.

Is any way to call this function with setting last argument and without setting other argument?

See this example:

function MyFunction($A, $B, $C, $D, $E, $F)
{
    //// Do something
}

//// Simple way
MyFunction("", "", "", "", "", "Value");

//// My example
MyFunction(argument6: "Value")

解决方案

My suggestion is use array instead of using number of argument, For example your function call should be like this.

$params[6] = 'value';
MyFunction($params);

For identify that sixth parameter has set

function MyFunction($params){
 If ( isset($params[6]) ) // parameter six has value

 }

I hope that it will be a alternate way

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

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