2015-07-30 21:02
浏览 51

如何从字符串变量创建一个php数组? [重复]

This question already has an answer here:

How to create an array from a string variable? This is the script I tried but it didn't work:

$names = '"Darius","Fiora","Katarina","Zed","Ahri","Lee sin"';
$array = array($names);

图片转代码服务由CSDN问答提供 功能建议

此问题已经存在 这里有一个答案:

  • 如何将字符串转换为php中的数组 10 answers

    如何从字符串变量创建数组? 这是我尝试过的剧本,但它不起作用:

      $ names ='“Darius”,“Fiora”,“Katarina”,“Zed”,“Ahri”  ,“Lee sin”'; 
     $ array = array($ names); 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doufeixuan8882 2015-07-30 21:07

    I dont think explode is what he wants, as it can add " to the elements in the array.

    If your string is pretty SURE formatted, eval function is an optional choice (more efficient):

    $names = '"Darius","Fiora","Katarina","Zed","Ahri","Lee sin"';

    See result

    NOTE: plz note eval is some danger if your string is not that certain, as @jay mentioned.

    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题