Tools, FAQ, Tutorials:
Function Returns Data by Value in PHP
How Values Are Returned from Functions? in PHP?
✍: FYIcenter.com
If a value is returned from a function, it is returned by value, not by reference. That means that a copy of the value is return. Here is a PHP script on how values are returned from a function:
<?php $favor = "vbulletin"; function getFavor() { global $favor; return $favor; } $myFavor = getFavor(); print("Favorite tool: $myFavor\n"); $favor = "phpbb"; print("Favorite tool: $myFavor\n"); ?>
This script will print:
Favorite tool: vbulletin Favorite tool: vbulletin
As you can see, changing the value in $favor does not affect $myFavor. This proves that the function returns a new copy of $favor.
⇒ Returning a Reference from a Function in PHP
⇐ Accessing Global Variables inside a Function in PHP
2016-12-08, ∼2247🔥, 0💬
Popular Posts:
How To Read Data from Keyboard (Standard Input) in PHP? If you want to read data from the standard i...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...
How to add request query string Parameters to my Azure API operation to make it more user friendly? ...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...