字符串“ array”到实数组 [英] String "array" to real array
本文介绍了字符串“ array”到实数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我得到了一个数组的字符串,像这样:
Now I got the string of an array, like this :
$str = "array('a'=>1, 'b'=>2)";
如何将该字符串转换为实数数组?是否有其他使用explode()的智能方式来做到这一点?因为字符串数组在某些时候可能会非常复杂。
How can I convert this string into real array ? Is there any "smart way" to do that, other that use explode() ? Because the "string" array could be very complicated some time.
谢谢!
推荐答案
我不知道这样做的好方法(只有邪恶的 eval()
到应避免使用真正的)。
i don't know a good way to do this (only evil eval()
wich realy should be avoided).
但是:您从哪里获得该字符串?您会影响到它吗?如果是这样,使用 serialize()
/ unserialize()
是一种更好的方法。
but: where do you get that string from? is it something you can affect? if so, using serialize()
/ unserialize()
would be a much better way.
这篇关于字符串“ array”到实数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文