Is there a way to send parameters to a callback function without first creating my own function?

I have an array of values ​​that I would like to run through htmlspecialchars, but with an argument like this:

$param = htmlspecialchars($param, ENT_QUOTES);

The problem is that I have an array of values ​​that I want to run htmlspecialchars:

$array = array_map('htmlspecialchars', $array);

and I would like to know if there is a way to pass ENT_QUOTES to the array_map callback?

I can always use my own function that uses htmlspecialchars, but it would be nice if there was a way to do this already.


After the answer below, here is my final result:

$array = array_map('htmlspecialchars', $array, array_fill(0, count($array), ENT_QUOTES));

Which just fills the array with as many values ​​as the $ array, and it is filled with ENT_QUOTE.

+5
2

, array_map, ENT_QUOTES, $array:

$quote_style = ENT_QUOTES;
$array = array('"',"'","''''''''''''\"");
$ent_quotes_array = array($quote_style, $quote_style, $quote_style);
$array = array_map('htmlspecialchars', $array, $ent_quotes_array);
print_r($array);

, :

$array = array('"',"'","''''''''''''\"");
$ent_quotes_array = array_fill(0, sizeof($array), ENT_QUOTES);
$array = array_map('htmlspecialchars', $array, $ent_quotes_array);
+3

...

function change_values_for_encode_output(&$item, $key) {
    $item = htmlentities($item, ENT_QUOTES);
}

function encode_output_vars($vars) {
    if(is_array($vars)) {
        array_walk_recursive($vars, 'change_values_for_encode_output');
        return $vars;
    }
    else {
        $vars = htmlentities($vars, ENT_QUOTES);
                    return $vars;
    }
}
0

All Articles