When would there ever be an array stored within one of the $POST or $GET keys? I ran accross this code which is part of a larger function to clean the incoming form data values, and I can't figure out when there would ever be an array stored within one of these arrays, nor could I figure out why it would be important to run the key for that array through the given clean_key function:
if ( is_array( $_GET ) )
{
foreach ( $_GET as $key => $val )
{
if ( is_array( $_GET[ $key ] ) )
{
foreach ( $_GET[ $key ] as $key2 => $val2 )
{
$output[ $key ][ clean_key($key2) ] = clean_value($val2);
}
}
else
{
$output[ $key ] = clean_value($val);
}
}
}
if( is_array( $_POST ) )
{
foreach ( $_POST as $key => $val )
{
if ( is_array( $_POST[ $key ] ) )
{
foreach ( $_POST[ $key ] as $key2 => $val2 )
{
$output[ $key ][ clean_key($key2) ] = clean_value($val2);
}
}
else
{
$output[ $key ] = clean_value($val);
}
}
}
function clean_key($key)
{
if ($key == '')
{
return '';
}
$key = preg_replace( "/\.\./" , "" , $key );
$key = preg_replace( "/\_\_(.+?)\_\_/" , "" , $key );
$key = preg_replace( "/^([\w\.\-\_]+)$/", "a$1", $key );
return $key;
}