I have an array of values that I would like to run through htmlspecialchars but with an argument such as this:
$param = htmlspecialchars($param, ENT_QUOTES);
The problem is, I have an array of values that I want to run htmlspecialchars on:
$array = array_map('htmlspecialchars', $array);
and I would like to know if there is a way to pass ENT_QUOTES into 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 end result:
$array = array_map('htmlspecialchars', $array, array_fill(0, count($array), ENT_QUOTES));
Which simply fills an array with as many values as $array has and it's filled with ENT_QUOTE.
This should work if you pass a second array as parameter to
array_map
that will contain as manyENT_QUOTES
elements as your number of elements in$array
:Or, a little bit more elegant:
Here is my output helper function...