Re: Pass Variable Names to a Function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



function silly($var){
  return isset($_SESSION[$var]) ? $_SESSION[$var] : '';
}

silly('foo');

On Fri, February 1, 2008 10:49 am, Bill Guion 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";
>    if (isset($_SESSION['$var']))
>      {
>      return $_SESSION['$var'];
>      }
>    else
>      {
>      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?
>
>       -----===== Bill =====-----
> --
>
> Diplomacy - telling your boss he has an open mind
> instead of saying he has a hole in his head.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux