background image

PHP 函数参数传递方法的优化技巧

当我们在写 PHP 代码的时候,经常会需要对代码进行多次的升级更改等,这样来回

不断的重复修改参数,会使我们的整个程序性能降低,并增加了不少的工作量。我们今天
就为大家介绍一下是使用数组进行 PHP 函数参数传递方法的赶紧。

本人在经历了多次重复操作之后决定改进一下传统 PHP 函数参数传递方法,使用数

组作为参数,请看下面的例子.

先看一个传统的自定义函数

1. /**  

2. * @Purpose:     

 

插入文本域  

3. * @Method Name: addInput()  

4.

* @Parameter:    str $title        

 

表单项标题  

5. * @Parameter:    str $name        

 

元素名称  

6. * @Parameter:    str $value        

 

默认值  

7. * @Parameter:    str $type        类型,默认为 text,可选 password  

8. * @Parameter:    str $maxlength        

 

最长输入  

9. * @Parameter:    str $readonly        

 

只读  

10. * @Parameter:    str $required        是否必填,默认为 false,true

 

为必填  

11. * @Parameter:    str $check        表单验证 function(js)

 

名称  

12. * @Parameter:    str $id            元素 id,

 

无特殊需要时省略  

13. * @Parameter:    int $width        元素宽度,单位:

 

象素  

14. * @Parameter:    str $tip        

 

元素提示信息  

15. * @Return:        

16. */  

17.

function addInput($title,$name,$

value

=

""

,$

type

=

"text"

,$

maxlength

=

"255"

,

$readonly,$

required

=

"false"

,$check,$id,$width,$tip)  

18. {  

19.

    $this-

>

form 

.

"<li>\n"

;  

20.

    $this-

>

form 

.

"<label>"

.$title.":

</label>

\n";  

21.

    $this-

>

form 

.

= "

<input

 name=\"

".$name."

\" 

value

=\"".$value."\" 

typ

e

=\""

.$type."\" 

maxlength

=\"".$maxlength."\" 

required

=\"".$required."\" 

chec

k

=\""

.$check."\" 

id

=\"".$id."\" 

class

=\"input\" ".$readonly." 

styl

e

=\"width:".$width.

"px;\" 

showName

=\"".$title."\" 

/>

 ";  

22.

    $this-

>

form 

.

= "

<span

 class=\"

tip

\"

>

".$tip."

</span>

\n";  

23.

    $this-

>

form 

.

"</li>\n"

;  

24. } 

这是我写的表单类中一个插入文本框的函数.