By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

Filtering the elements of a multi-dimensional array

P: n/a
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.

Any suggestions?

Thanks,
Geoff

--
Remove nospam in email address to reply
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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)
Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.