【问题标题】:a string with a content of array to a new array php [closed]具有数组内容的字符串到新数组php [关闭]
【发布时间】:2012-12-28 03:30:33
【问题描述】:

我在 html 中有一个表单,它会采用一个巨大的字符串,后面用空格、逗号和一个空格分隔,每个项目都用引号括起来,如下所示:

$s = '"info1" , "info2"'; //and so on

所以我的问题是如何创建一个新的数组变量并将字符串中的信息设置为数组中的信息?基本上是这样的:

$array_ex = array("info1", "info2"); //of course there is going to be
                                     //way more than 2 items

有可能吗?

谢谢!

【问题讨论】:

标签: php arrays string function


【解决方案1】:
$s = '"info1" , "info2"' //and so on

$array = explode(",",$s);


print_r($array)

【讨论】:

    【解决方案2】:

    explode 函数用于从具有特定分隔符的字符串生成数组。

    作为上述问题的解决方案,您需要使用 explode 函数从用逗号分隔的字符串生成数组

    例如

            $a=explode(",",$string);
    

    更多关于爆炸功能的详细信息,请参考以下网址中提到的文档

    http://php.net/manual/en/function.explode.php

    【讨论】:

      猜你喜欢
      • 2013-06-30
      • 2014-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多