PHP

Topic: Functions

How Values Are Returned from Functions?

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: vbulletinFavorite tool: vbulletinAs you can see, changing the value in $favor does not affect $myFavor. This proves that the function returns a new copy of $favor.

Browse random answers: