Re: array_map help

From: Date: Fri, 17 Feb 2006 17:23:52 +0000
Subject: Re: array_map help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-230649@lists.php.net to get a copy of this message
Mark Steudel wrote:
I've got the following code and I am not doing something right. Either my function is wrong, or the way Im using array_map is wrong, as slashes are still making it into the data, and the asdf iosn't getting appended to each value.
I rewrote what you had like so: <?php function detectMGQ($value) { //return get_magic_quotes_gpc() ? stripslashes($value): $value; return $value."-TEST"; } $clean = array(
    "name"          => "name",
    "email"         => "email",
    "username"      => "username",
    "accesslevel"   => "accesslevel",
    "status"        => "status",
); $field_values = array_map( "detectMGQ", $clean ); var_dump($field_values); ?> and it adds '-TEST' to every value as expected. not sure whats going wrong with your code exactly by I have got some general comments... (maybe the code I rewrote helps you to figure otu what was/is going wrong.)
Thanks, Mark // function to remove stripped slashes function detectMGQ($value) { // Stripslashes if (get_magic_quotes_gpc()) {
       $value = stripslashes($value);
}
    // added in to detect if this function is working
$value .= $value.'asdf';
if $value equals "ABC" then it would equal "ABCABCasdf" aftyer that last line of code was run.
return $value; } // construct field and value pairs into array $field_values = array( 'name' => "$clean[name]", 'email' => "$clean[email]",
yuou don't need to wrap $clean[email] in quotes - it's waste of time+cpu BUT you should always delimit the array key with quotes because it is a string not a constant (or does you code actually define a constant named 'email'?) i.e. "$clean[email]" is better off being $clean['email']
'username' => "$clean[username]", 'accesslevel' => "$clean[accesslevel]", 'status' => "$clean[status]", 'password' => base64_encode(rc4($clean[password1])) ); // walk through the values and strip out the slashses $field_values = array_map( "detectMGQ", $field_values );


« previous php.general (#230649) next »