1/**
2 * Encode array from latin1 to utf8 recursively
3 * @param $dat
4 * @return array|string
5 */
6 public static function convert_from_latin1_to_utf8_recursively($dat)
7 {
8 if (is_string($dat)) {
9 return utf8_encode($dat);
10 } elseif (is_array($dat)) {
11 $ret = [];
12 foreach ($dat as $i => $d) $ret[ $i ] = self::convert_from_latin1_to_utf8_recursively($d);
13
14 return $ret;
15 } elseif (is_object($dat)) {
16 foreach ($dat as $i => $d) $dat->$i = self::convert_from_latin1_to_utf8_recursively($d);
17
18 return $dat;
19 } else {
20 return $dat;
21 }
22 }
23// Sample use
24// Just pass your array or string and the UTF8 encode will be fixed
25$data = convert_from_latin1_to_utf8_recursively($data);