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

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

WBOY
Release: 2016-06-13 12:09:46
Original
1455 people have browsed it

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

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


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

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

<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 />
Copy after login

Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template