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

后端 未结 13 1704
盖世英雄少女心
盖世英雄少女心 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:

    <?PHP
        $array = array("firstname"=>"John", "lastname"=>"doe");
        $json = json_encode($array);
        $phpStringArray = str_replace(array("{", "}", ":"), 
                                      array("array(", "}", "=>"), $json);
        echo phpStringArray;
    ?>
    
    0 讨论(0)
提交回复
热议问题