";"/> ";">

Home>Article>Backend Development> Detailed explanation of the usage of value transfer/reference transfer between PHP custom functions

Detailed explanation of the usage of value transfer/reference transfer between PHP custom functions

伊谢尔伦
伊谢尔伦 Original
2017-06-26 09:33:15 1134browse

php:Parameter transfer between functions

1. Value transfer

"; } $var1 = 1; echo $var1 . "
"; exam($var1); echo $var1 . "
"; ?>

------------------------------------------------ -------------------------------
Output results:
1
In Exam: 2
1
---------------------------------------------- ----------------------------------
2.QuoteTransfer

"; } $var1 = 1; echo $var1 . "
"; exam($var1); echo $var1 . "
"; ?>

----------------------------------------- ---------------------------------------------
Output result:
1
In Exam: 2
2
--------------------------------------------- ----------------------------------------
3.Yes Select parameter

function values($price, $tax=""){ $price += $prive * $tax; echo "Total Price:" . $price . "
"; } values(100, 0.25); values(100);

Output result:
Total Price: 125
Total Price: 100
------------------ -------------------------------------------------- -----------
4. If aobjectis passed in, the value of the object can be changed
(actuallyVariable$obj records the handle of this object. Passing $obj as a parameter can completely operate on the original object)

name = $name; $this->age = $age; $this->gander = $gander; } public function show_info(){ echo $this->name . " " . $this->age . " " . $this->gander . "
"; } } function grow($obj){ $obj->age++; } function test(){ $obj = new Obj("Mr. zhan", "12", "male"); $obj->show_info(); grow($obj); $obj->show_info(); grow($obj); $obj->show_info(); } test(); ?>

----------- -------------------------------------------------- ------------------
Output result:
Mr. zhan 12 male
Mr. zhan 13 male
Mr. zhan 14 male

The above is the detailed content of Detailed explanation of the usage of value transfer/reference transfer between PHP custom functions. For more information, please follow other related articles on the PHP Chinese website!

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