PHP array encoding conversion example. The final function is as follows: code functionarray_iconv ($ in_charset, $ out_charset, $ arr) {returneval (return. iconv ($ uses the serialization method to build an array prototype. with the var_export function, the final function is as follows:
| The code is as follows: |
|
|
Function array_iconv ($ in_charset, $ out_charset, $ arr ){
Return eval ('Return '. iconv ($ in_charset, $ out_charset, var_export ($ arr, true ).';'));
} |
The principle is simple. var_export sets the second parameter to true, returns the array prototype string, converts the string to UTF-8 encoding, and then uses eval to execute the return (similar to the anonymous function ?), This is a perfect solution.
Another idea in the Yiju tutorial is to use foreach to traverse the array and then use the ionv function to convert the array values one by one. However, the array values are converted in this way.
The callback code is as follows: function array_iconv ($ in_charset, $ out_charset, $ arr) {return eval ('Return '. iconv ($...