Skip to content

Instantly share code, notes, and snippets.

@githubnando
Last active June 23, 2017 13:38
Show Gist options
  • Save githubnando/b70f931a373d9a12cd921b3b220ec110 to your computer and use it in GitHub Desktop.
Save githubnando/b70f931a373d9a12cd921b3b220ec110 to your computer and use it in GitHub Desktop.
Recursively encode to UTF-8 a given array
<?php
# Recursively encode to UTF-8 a given array
public function utf8(array $array)
{
array_walk_recursive($array, function(&$item, $key) {
if(is_string($item) && ! mb_detect_encoding($item, 'utf-8', true)) {
$item = utf8_encode($item);
}
});
return $array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment