Home >Backend Development >PHP Tutorial >function 里面如何定义ref 输出的参数

function 里面如何定义ref 输出的参数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:09:461464browse

function 里面怎么定义ref 输出的参数?
类似asp那种的,

<br />function fo($a,$b,$cheng,$jia)<br />{<br />  $cheng = $a*$b;<br />  $jia = $a + $b;<br />}<br />


------解决思路----------------------
你的函数 fo 的参数 $cheng 和 $jia 是作为计算结果出现的
所以定义时应这样
function fo($a, $b, &$cheng, &$jia)<br />{<br />  $cheng = $a*$b;<br />  $jia = $a + $b;<br />}

------解决思路----------------------
使用引用。

<br />function fo($a,$b,&$cheng,&$jia)<br />{<br />  $cheng = $a*$b;<br />  $jia = $a + $b;<br />}<br /><br />fo(1,2,$cheng, $jia);<br /><br />echo $cheng; // 2<br />echo $jia;   // 3<br />

Statement:
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