Re: return

From: Date: Mon, 01 Apr 2002 07:09:11 +0000
Subject: Re: return
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-90931@lists.php.net to get a copy of this message
Gary, To add to the conversation ... You created a function to pass something through it, to process something and now you want to get something back, right? That's what return does. It gets something back for your effort. You could simply: echo addslashes($var); But let's say you do it a hundred times in the course of a script. You don't want to take up a hundred lines of code doing: echo addslashes($var); ... so you create a function like Eric has below, which takes up 3 or 4 lines of code, but has the capacity to repeat the same line of code 100 times. John > The purpose of return, is to "return" a value.. > function test($var) > { > return addslashes($var); > } > > $foo = "Yes, I'am Very Awsome"; > $foo = test($foo); > echo($foo); > // echo's, Yes I\'am Very Awsome

« previous php.general (#90931) next »