On Thu, 4 Dec 2003 21:02:51 -0000, "Geoff Soper" <ne*********@alphaworks.co.uk>
wrote:
I would like to be able to filter every element of a multi-dimensional array
using htmlspecialchars() and to retain the structure of the array. I can't
see how to do this when I don't know how many dimensions the array has.
<pre>
<?php
$a = array(
array(
array('&', '&', '&'),
'&',
array('&', '&')
),
'&',
array('&', '&', '&'),
);
print_r($a);
function htmlspecialcharsArray(&$a) {
foreach (array_keys($a) as $key)
if (is_array($a[$key]))
htmlspecialcharsArray($a[$key]);
else
$a[$key] = htmlspecialchars($a[$key]);
}
htmlspecialcharsArray($a);
print_r($a);
?>
</pre>
So long as you don't set up any loops in your arrays, of course :-)
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (
http://www.andyh.co.uk)
Space: disk usage analysis tool (
http://www.andyhsoftware.co.uk/space)