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

WBOY
Release: 2016-06-23 13:45:13
Original
804 people have browsed it

类似asp那种的,

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


回复讨论(解决方案)

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

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

使用引用。

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

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!