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

WBOY
Freigeben: 2016-06-13 13:33:49
Original
1240 Leute haben es durchsucht

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)
  }


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

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!