Generating a JavaScript array from a PHP array

前端 未结 2 940
名媛妹妹
名媛妹妹 2020-12-04 00:14

Suppose that I have a string $var:

//php code

$var = \"hello,world,test\";
$exp = explode(\",\",$var);

Now I get the array as

2条回答
  •  长情又很酷
    2020-12-04 00:29

    I would have thought json_encode would be the most reliable and simplest way.

    E.g.

    $var = "hello,world,test";
    $exp = explode(",",$var);
    print json_encode($exp);
    

提交回复
热议问题