Re: return

From: Date: Mon, 01 Apr 2002 05:56:02 +0000
Subject: Re: return
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-90926@lists.php.net to get a copy of this message
On Sun, 31 Mar 2002, Miguel Cruz wrote: > On Mon, 1 Apr 2002, Jordan wrote: >> Isnt there really no need for the 'return' though? > > Try this program and see what happens: Ah, Rasmus brings up a good point. Try this one instead. <? function triple1($x) { $x = $x * 3; return $x; } function triple2($x) { $x = $x * 3; } function triple3($x) { global $x; $x = $x * 3; } function triple4(&$x) { $x = $x * 3; } $x = 5; $x = triple1($x) print '<p>triple1: ' . $x; $x = 5; print '<p>triple1 return: ' . triple1($x); $x = 5; $x = triple2($x) print '<p>triple2: ' . $x; $x = 5; print '<p>triple2 return: ' . triple2($x); $x = 5; $x = triple3($x) print '<p>triple3: ' . $x; $x = 5; print '<p>triple3 return: ' . triple3($x); $x = 5; $x = triple4($x) print '<p>triple4: ' . $x; $x = 5; print '<p>triple4 return: ' . triple4($x); ?> miguel

« previous php.general (#90926) next »