Home > Backend Development > PHP Tutorial > PHP代码的输出结果解决思路

PHP代码的输出结果解决思路

WBOY
Release: 2016-06-13 13:38:53
Original
960 people have browsed it

PHP代码的输出结果

  $sum=10;
  function demo($number){
  $number=$number+20;
  }
  demo(&$num);
  echo $num,"\n";
   
?>
结果为什么是20,而不是30?

------解决方案--------------------

你这个不对,结果是10,$num是全局变量

应该改为

$num=10;
function demo($number)
{
$number=$number+20;
return $number;
}
$num = demo($num);
echo $num,"\n";

这样结果才是30

探讨

PHP code

/*
Deprecated: Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of demo(). If you would like to enable call-time pass-by-r……

------解决方案--------------------
$num=10;
function demo(&$number){
$number=$number+20;
}
demo($num);
echo $num,"\n";

如果是这个意思,那么结果是30
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