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, ∼3050🔥, 0💬
Popular Posts:
What validation keywords I can use in JSON Schema to specifically validate JSON Array values? The cu...
How To Break a File Path Name into Parts in PHP? If you have a file name, and want to get different ...
How to Instantiate Chaincode on BYFN Channel? You can follow this tutorial to Instantiate Chaincode ...
How to extend json.JSONEncoder class? I want to encode other Python data types to JSON. If you encod...
How to dump (or encode, serialize) a Python object into a JSON string using json.dumps()? The json.d...