Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2001032

[PHP] renaming form posted variable names From: David Minor (dave <email protected>)
Date: 03/30/01

I've got a logic problem that I just can't think through. I'm hoping that
you can help me find a better way to do this. I need a function that will
iterate through $HTTP_POST_VARS looking for variable names with a predefined
suffix ($example_post). Then I want to save the value of this var in a
variable named $example. The code that I already have successfully does the
iteration and selection of vars. What I can't do is make the new var
($example) accessible to the rest of the script. How should I do this?

<PRE>
function do_each($passed_array) {
    
global ${$tmp_var_name};

    if (substr($passed_array[0],-5) == "_post") {
        $tmp_var_name = substr($passed_array[0],0,-5);
        ${$tmp_var_name} = $passed_array[1];
        return(${$tmp_var_name});
    }
}

function conv_vars($input) {

global ${$tmp_var_name};

    if (IsSet($input)) {
        while ($each_array = each($input)) {
           if (is_array($each_array[1])) // if nested array
                conv_vars($each_array[1]); // pass to self
            else
                $new_var_value = do_each($each_array);
        }
    }
}

conv_vars($HTTP_POST_VARS);

</PRE>

Thanks in advance for the help. I learn so much from this list!
dm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>