Ask your boss a simple question, how do you convert the character set of an array?
For strings, there is a mb_convert_encoding () function.
But what about an array? Do you want to cycle through this function:
Array_map (
function ($value) use ($from, $to) {return mb_convert_encoding ($value, $from, $to);},
$input
);
This creates an efficiency problem, and if a big data is weak, it explodes.
Can it be processed at once, with such built-in functions? or other solutions?
Share to:
------Solution--------------------
Array_walk, Array_walk_recursive
But I just got the loop inside.
But it's always going to be faster than your recursive loop.
You can't array_map the light! If the multidimensional array is powerless,
You can also use iterators
In fact, the character set is only required for conversion when input and output
Input (such as a read database), MySQL will give you the character set you need, do not need to convert
Output can be completed via Ob_start
Mb_internal_encoding ("GBK");
Mb_http_output ("Utf-8"); To output to Utf-8.
Ob_start (' Mb_output_handler '); That's all you need.
And then the output becomes utf-8.