Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save esthezia/5804445 to your computer and use it in GitHub Desktop.
Save esthezia/5804445 to your computer and use it in GitHub Desktop.
PHP - Sanitize a multidimensional array
<?php
/**
* Sanitize a multidimensional array
*
* @uses htmlspecialchars
*
* @param (array)
* @return (array) the sanitized array
*/
function purica_array ($data = array()) {
if (!is_array($data) || !count($data)) {
return array();
}
foreach ($data as $k => $v) {
if (!is_array($v) && !is_object($v)) {
$data[$k] = htmlspecialchars(trim($v));
}
if (is_array($v)) {
$data[$k] = purica_array($v);
}
}
return $data;
}
@hieronymusdesign
Copy link

Thanks, mind if i take this. Was looking for it ;)

Regards Jerome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment