Home >Backend Development >PHP Tutorial >function 里面怎么定义ref 输出的参数?

function 里面怎么定义ref 输出的参数?

WBOY
WBOYOriginal
2016-06-23 13:45:13837browse

类似asp那种的,

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


回复讨论(解决方案)

你的函数 fo 的参数 $cheng 和 $jia 是作为计算结果出现的
所以定义时应这样

function fo($a, $b, &$cheng, &$jia){  $cheng = $a*$b;  $jia = $a + $b;}

使用引用。

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

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