Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code explanation ...

Status
Not open for further replies.

dbeezzz

Technical User
Nov 30, 2005
54
KR
So I came across this piece of code to-day. I'm reasonably familiar with variable variables but I still don't really get this.
It's used to enumerate the value element of a submitted form's name-value pair. So that if your name-value pair was hidden=submit. Then you'd end up with a variable $submit, which could be used to guide your script eg.
Code:
if ($submit){ // then other code here}
... anyway this is the code
Code:
$params = array('submit' => 'hidden', 'style' => 'style' );

while( list($var, $param) = @each($params) )
{
	if ( !empty($HTTP_POST_VARS[$param]) || !empty($HTTP_GET_VARS[$param]) )
	{
		$$var = ( !empty($HTTP_POST_VARS[$param]) ) ? htmlspecialchars($HTTP_POST_VARS[$param]) : htmlspecialchars($HTTP_GET_VARS[$param]);
// MY test_var function here test_var($$var);
	}
	else
	{
		$$var = '';
	}
}
this is my a var_dump of $_POST and the results from test_var($$var)
Code:
array(2) { ["hidden"]=>  string(6) "submit" ["style"]=>  string(7) "Classic" }

the value of submit is submit

the value of Classic is default value for presentation
????
 
the code looks old-style but not incorrect. there are neater ways of obtaining the same result.

i'm not sure what your question is? if the results are not what you expected, please post also your test_vars function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top