Home  >  Article  >  Backend Development  >  php数组编码转换出错解决方法

php数组编码转换出错解决方法

WBOY
WBOYOriginal
2016-06-13 13:33:491252browse

php数组编码转换出错
public function array_iconv($in_charset,$out_charset,$arr){
return eval('return '.iconv($in_charset,$out_charset,var_export($arr,true).';'));
}
我用上面的方法转化下面的数组出错
Fatal error: Call to undefined method stdClass::__set_state() in D:\soft\apache\htdocs\webtest\arrayiconv.func.php(5) : eval()'d code on line 1

array(5) {
  [0]=>
  object(stdClass)#8 (6) {
  ["optionContent"]=>
  string(4) "没有"
  ["optionId"]=>
  int(4137)
  ["optionImage"]=>
  NULL
  ["optionScore"]=>
  int(0)
  ["optionSortId"]=>
  string(1) "A"
  ["quesId"]=>
  int(1245)
  }
  [1]=>
  object(stdClass)#9 (6) {
  ["optionContent"]=>
  string(8) "几乎没有"
  ["optionId"]=>
  int(4138)
  ["optionImage"]=>
  NULL
  ["optionScore"]=>
  int(1)
  ["optionSortId"]=>
  string(1) "B"
  ["quesId"]=>
  int(1245)
  }
  [2]=>
  object(stdClass)#10 (6) {
  ["optionContent"]=>
  string(4) "有时"
  ["optionId"]=>
  int(4139)
  ["optionImage"]=>
  NULL
  ["optionScore"]=>
  int(2)
  ["optionSortId"]=>
  string(1) "C"
  ["quesId"]=>
  int(1245)
  }
  [3]=>
  object(stdClass)#11 (6) {
  ["optionContent"]=>
  string(4) "经常"
  ["optionId"]=>
  int(4140)
  ["optionImage"]=>
  NULL
  ["optionScore"]=>
  int(3)
  ["optionSortId"]=>
  string(1) "D"
  ["quesId"]=>
  int(1245)
  }
  [4]=>
  object(stdClass)#12 (6) {
  ["optionContent"]=>
  string(4) "总是"
  ["optionId"]=>
  int(4136)
  ["optionImage"]=>
  NULL
  ["optionScore"]=>
  int(4)
  ["optionSortId"]=>
  string(1) "E"
  ["quesId"]=>
  int(1245)
  }


------解决方案--------------------
老老实实递归遍历吧……

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