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, ∼2914🔥, 0💬
Popular Posts:
How to create a navigation file like navigation.xhtml for an EPUB 3.0 book? At least one navigation ...
How To Set session.gc_divisor Properly in PHP? As you know that session.gc_divisor is the frequency ...
How to how to use matched string and groups in replacements with re.sub()? When calling the re.sub()...
Where to find tutorials on HTML language? I want to know how to learn HTML. Here is a large collecti...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...