【发布时间】:2013-05-04 13:59:03
【问题描述】:
这可能是一个简单的问题,但是我如何将如下所示的变量放入数组中。
$hot = "It","is","hot","outside";
执行以下操作无效:
$newhot = array($hot);
我实际上调用的 API 如下所示:
[["P0010001","NAME","state","zip code tabulation area"],
["68191","ZCTA5 99301","53","99301"]]
我需要的是第二行的人口(第一个引号)。
执行以下操作会给我 "68191","ZCTA5 99301","53","99301"
$splitContent = implode("\n",array_slice(explode("\n",$populate),1,2));
$newContent = str_replace(']','',$splitContent);
$newContent = str_replace('[','',$newContent);
【问题讨论】:
-
这看起来像是语法错误。
-
$hot = "It","is","hot","outside";不是变量
-
json_decode($populate);? -
正在做:$NewContent = json_decode($populate);回声 $NewContent[0];返回页面上的数组