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, 1731🔥, 0💬
Popular Posts:
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...
What is the "__init__()" class method? The "__init__()" class method is a special method that will b...
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...
How to build a PHP script to dump Azure AD 2.0 Authentication Response? If you are use the Azure-AD-...
What is Azure API Management Developer Portal? Azure API Management Developer Portal is an Azure Web...