What I do when I need multidimensional arrays from forms, is name my
variables:

    <INPUT NAME="i::foo::bar" VALUE=" ... ">

i.e., I delimit the dimensions with "::".  Then, on the page they are posted
to, I do:

<?
    parseInputVars('i');
?>

And here is the code for that function, which looks for all the variables
that start with 'i::' and creates the multidimensional array needed.

<?
###############################################################
#
#   parseInputVars
#
#   - parses HTTP_POST variables into a multi-dimensional
#     arary, using '::' as the delimiter, and also runs
#     a function on each element of the array during parsing,
#     and optionally another function on the entire array
#     after parsing
#

function parseInputVars($var, $function=false, $global_function=false) {
    global $HTTP_POST_VARS, $$var;

    if (is_array($HTTP_POST_VARS)) {

        $temp = '';
        foreach($HTTP_POST_VARS as $k=>$v) {
            $s = explode('::',$k);
            if ($s[0] == $var) {
                $s2 = array();
                foreach ($s as $k2=>$v2) {
                    if ($k2) {
                        $s2[] = $v2;
                    }
                }
                if (is_object($v) || is_array($v)) {
                    $temp .= sprintf("\$t[%s] =
unserialize(urldecode(\"%s\"));",
                        join('][',$s2), urlencode(serialize($v))
                    );
                } else {
                    if ($function) {
                        $temp .= sprintf("\$t[%s] = %s(urldecode(\"%s\"));",
                            join('][',$s2), $function, urlencode($v)
                        );
                    } else {
                        $temp .= sprintf("\$t[%s] = urldecode(\"%s\");",
                            join('][',$s2), urlencode($v)
                        );
                    }
                }
            }
        }
        eval($temp);
        $$var = $t;

        if ($global_function) {
            $global_function($$var);
        }
    }
}
?>



--
Colin Viebrock
Co-Founder, easyDNS Technologies Inc.
http://www.easyDNS.com/




-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to