Re: array to var - with different name

From: Date: Thu, 20 Jan 2011 23:29:01 +0000
Subject: Re: array to var - with different name
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-310931@lists.php.net to get a copy of this message
Tommy Pham wrote: [snip]
foreach ($_REQUEST as $key => $value) $$key = $value; short-circuited one-liners :) Regards, Tommy
akk... wrong clicked before I had a chance to fix the code. anyway, foreach ($_GET as $key => $value) if (substr($key, 0, 2) == 'f_') ${'t_'.substr($key, 2)} = $value;
Tommy, excellent.. I had just rewrote your first suggestion: foreach ($a_formvars as $key => $value) ${str_replace('f_', 't_',$key)} = $value; (which works) but I like that you are only affecting the vars that *begin* with $match. I suppose the above would also work with $_REQUEST. Shawn, I don't know if I have a good reason, other than I rather like working with string vars instead of array vars from $_REQUEST for (sticky forms and conditionals). I can check/verify them as well in the process. Thanks to all that posted.. I always learn from the "skin the cat" game. Donovan -- D Brooke

« previous php.general (#310931) next »