Re: Pass Variable Names to a Function
| From: | Greg Donald | Date: | Fri, 01 Feb 2008 16:57:21 +0000 |
| Subject: | Re: Pass Variable Names to a Function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268534@lists.php.net to get a copy of this message | ||
On Feb 1, 2008 10:49 AM, Bill Guion <bguion@comcast.net> wrote:
> I would like to use a function to check to see if a session variable
> is set and return the session variable if it is set, and return blank
> if not. Something like
>
> function set_var($var)
> {
> echo "var = $var \n";
echo "\$var = $var\n"; // :)
> if (isset($_SESSION['$var']))
$_SESSION[$var]
> {
> return $_SESSION['$var'];
$_SESSION[$var]
> }
> else
> {
> return "";
return '';
> }
> }
>
> And I would call the function with set_var($name) or set_var($phone).
> The problem is getting the function to use $var as a variable name,
> rather than a value. What am I missing, please?
"" means interpolate the contents.
'' means use the literal content.
--
Greg Donald
http://destiney.com/