doulu6929 2016-04-29 09:32
浏览 471
已采纳

将PHP字符串数组转换为Array对象

I'm developing a PHP app and I have a problem by converting a string array into an object array. I tried to force casting my string into an array by using (array), but it won't works. Here is my string (debug):

string '['method'=>'post','action'=>'#']' (length=32)

As you can see, it's a perfect array into a string and i want to convert that string.

My question is simple, does PHP has a function to convert directly a string into an array (I think no) or i have to convert my string by using explode?

  • 写回答

3条回答 默认 最新

  • douzhuo3233 2016-04-29 09:42
    关注

    From php 5.4 you can simply eval: eval("\$f=['method'=>'post','action'=>'#'];"); var_dump($f);

    For olders you have to fix the string a bit, change the 1st "[" to "array(" and the last "]" to ")".

    The question is a bit duplicate of How to create an array from output of var_dump in PHP?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧