php - How to make variable that's in an array format into an array -


this simple question, how take variable following , make array.

    $hot = "it","is","hot","outside"; 

doing following doesn't work:

    $newhot = array($hot); 

i'm calling api looks like:

    [["p0010001","name","state","zip code tabulation area"],     ["68191","zcta5 99301","53","99301"]] 

what need population on second line (first quotes).

doing following gives me "68191","zcta5 99301","53","99301"

    $splitcontent = implode("\n",array_slice(explode("\n",$populate),1,2));     $newcontent = str_replace(']','',$splitcontent);     $newcontent = str_replace('[','',$newcontent); 

this

$hot = "it","is","hot","outside"; 

will generate error in php. let's have following retrieved api:

$str='[["p0010001","name","state","zip code tabulation area"],["68191","zcta5 99301","53","99301"]]'; 

then, if run line:

$myarray = json_decode($str); 

and then

echo "<pre>"; print_r($myarray); echo"</pre>"; 

you can have result:

array (     [0] => array         (             [0] => p0010001             [1] => name             [2] => state             [3] => zip code tabulation area         )      [1] => array         (             [0] => 68191             [1] => zcta5 99301             [2] => 53             [3] => 99301         )  ) 

second line of data stored in

$myarray[1] 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -