Home > php教程 > php手册 > body text

PHP数组编码转换实例演示

WBOY
Release: 2016-06-13 09:44:10
Original
976 people have browsed it

   用构建数组原型的序列化方法,借助var_export函数,最终函数如下:

 代码如下  

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

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

}

  原理很简单 var_export设置第二个参数为true,返回数组原型字符串,将字符串转换为utf-8编码,之后再用eval来执行返回(类似匿名函数?),至此完美解决问题。

  一聚教程小编还有一个想法,就是利用foreach遍历数组然后再利用iocnv函数起先一个个转换了,不过这样转换的是把数组值进行转换了。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template