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, 1911🔥, 0💬
Popular Posts:
What Azure AD App Registration Manifest? Azure AD App Registration Manifest is JSON file that contai...
How To Create an Array with a Sequence of Integers or Characters in PHP? The quickest way to create ...
How to run CMD Commands in Dockerfile to change Windows Docker images? When building a new Windows i...
How to use the "Ctrl-p Ctrl-q" sequence to detach console from the TTY terminal of container's runni...
How to read RSS validation errors at w3.org? If your RSS feed has errors, the RSS validator at w3.or...