dongqian7545 2015-06-01 08:12
浏览 9
已采纳

PHP字符串表示为数组到数组

$var = "['test', 'test2', 'test3']";

how do I create a workable array from this in PHP?

I've tried explode($var, ","); but this didn't seem to work, unless something went wrong with that attempt.

  • 写回答

4条回答 默认 最新

  • douzhao4071 2015-06-01 08:14
    关注

    explode($var, ","); is wrong. explode needs the first argument to be the delimiter and the second be the string. Replace [] and then explode -

    $var = "['test', 'test2', 'test3']";
    
    $var = str_replace(array('[', ']'), '', $var);
    $arr = explode(',', $var);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?