Home >Backend Development >PHP Tutorial >PHP array encoding conversion example demonstration_PHP tutorial

PHP array encoding conversion example demonstration_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:39:561082browse

Using the serialization method of constructing an array prototype, with the help of the var_export function, the final function is as follows:

The code is as follows

function array_iconv($in_charset,$out_charset,$ arr){

 代码如下  

function array_iconv($in_charset,$out_charset,$arr){

return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));

}

return eval('return '.iconv($ in_charset,$out_charset,var_export($arr,true).';'));

}

The principle is very 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 perform the return (similar to an anonymous function?), thus solving the problem perfectly.

The editor of Yiju Tutorial has another idea, which is to use foreach to traverse the array and then use the iocnv function to convert one by one, but this conversion is to convert the array value.

http://www.bkjia.com/PHPjc/727589.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/727589.htmlTechArticle
Using the serialization method of constructing the array prototype, with the help of 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($...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn