PHP code output result & lt ;? Php & nbsp; $ sum = 10; & nbsp; functiondemo ($ number) {& nbsp; $ number = $ number + 20; & nbsp ;}& nbsp; demo (& amp; $ num); PHP code output result
$ Sum = 10;
Function demo ($ number ){
$ Number = $ number + 20;
}
Demo (& $ num );
Echo $ num, "\ n ";
?>
Why is the result 20 instead of 30?
------ Solution --------------------
This is incorrect. The result is 10 and $ num is a global variable.
Should be changed
$ Num = 10;
Function demo ($ number)
{
$ Number = $ number + 20;
Return $ number;
}
$ Num = demo ($ num );
Echo $ num, "\ n ";
The result is 30.
Discussion
PHP code
/*
Deprecated: Call-time pass-by-reference has been deprecated; If you wowould like to pass it by reference, modify the declaration of demo (). if you wowould like to enable call-time pass-by-r ......
------ Solution --------------------
$ Num = 10;
Function demo (& $ number ){
$ Number = $ number + 20;
}
Demo ($ num );
Echo $ num, "\ n ";
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service