- function Array_iconv ($in _charset, $out _charset, $arr) {
- Return eval (' Return '. Iconv ($in _charset, $out _charset,var_export ($arr, true). '; ');
- }
Copy Code
Principle Analysis: Var_export set the second argument to true, return the array prototype string, convert the string to Utf-8 encoding, and then use Eval to perform the return (like anonymous function?). ) to solve the problem perfectly.
Follow-up: The method found on the Internet, mostly using recursive call Iconv way, if the array elements too much or more dimension, performance is certainly not how, better is the way of native code, do not need to consider whether it is n-dimensional array or associative array, everything has been automatically completed, to ensure that the data before and after the array conversion.
From the length of the code and the comparison between the cycle and the original method, or the method of this article is good oh. |