Tools, FAQ, Tutorials:
Returning a Reference from a Function in PHP
How To Return a Reference from a Function? in PHP?
✍: FYIcenter.com
To return a reference from a function, you need to:
Here is a PHP script on how to return a reference from a function:
<?php
$favor = "vbulletin";
function &getFavorRef() {
global $favor;
return $favor;
}
$myFavor = &getFavorRef();
print("Favorite tool: $myFavor\n");
$favor = "phpbb";
print("Favorite tool: $myFavor\n");
?>
This script will print:
Favorite tool: vbulletin Favorite tool: phpbb
As you can see, changing the value in $favor does affect $myFavor, because $myFavor is a reference to $favor.
⇒ Specifying Argument Default Values in PHP
⇐ Function Returns Data by Value in PHP
2016-12-08, ∼2693🔥, 0💬
Popular Posts:
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...
How to Install Docker Desktop 2.5.0 on Windows 10? You can follow this tutorial to Install Docker De...
How to use the JSON to XML Conversion Tool at freeformatter.com? If you want to try the JSON to XML ...
Can You Add Values to an Array without Keys in PHP? Can You Add Values to an Array with a Key? The a...
What's Wrong with "while ($c=fgetc($f)) {}" in PHP? If you are using "while ($c=fgetc($f)) {}" to lo...