Convert the first element of an array to a string in PHP

后端 未结 13 1742
盖世英雄少女心
盖世英雄少女心 2020-12-05 02:00

I have a PHP array and want to convert it to a string.

I know I can use join or implode, but in my case array has only one item. Why do I

13条回答
  •  借酒劲吻你
    2020-12-05 03:00

    A simple way to create a array to a PHP string array is:

    "John", "lastname"=>"doe");
        $json = json_encode($array);
        $phpStringArray = str_replace(array("{", "}", ":"), 
                                      array("array(", "}", "=>"), $json);
        echo phpStringArray;
    ?>
    

提交回复
热议问题