Home > php教程 > php手册 > body text

如何正确实现PHP function函数扩展

WBOY
Release: 2016-06-13 11:10:00
Original
851 people have browsed it

我们在这篇文章中将会为大家详细介绍有关

PHP function函数扩展的代码示例:

  1.  ?php  
  2. function choose($name,$id,$task){  
  3. global $db_link;  
  4. .....  
  5. return $xx;   
  6. }  
  7. ?> 

在调用的页面,往往就是$tmp=choose($name,$id,$task);

换一种PHP function函数扩展方式就是:

<ol class="dp-xml">
<li class="alt"><span><span class="tag"><span> ?php  </span></span></span></li>
<li>
<span>function choose($name,$id,<br>$task,$</span><span class="attribute">instance</span><span>=</span><span class="attribute-value">0</span><span>){  </span>
</li>
<li class="alt"><span>global $db_link;  </span></li>
<li><span>.....  </span></li>
<li class="alt"><span>return $xx;   </span></li>
<li><span>}  </span></li>
<li class="alt">
<span class="tag">?></span><span> </span>
</li>
</ol>
Copy after login

这个函数的使用和平时没什么两样,只是当我们不传入$instance时,如

$array=choose($name,$id,$task);

它就是默认$instance=0来处理,当我们需要$instance来进行PHP function函数扩展时,我们调用的页面可以这样写:

$instance="...";
$array=choose($name,$id,$task,$instance)


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template