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

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

    You could use print_r and html interpret it to convert it into a string with newlines like this:

    $arraystring = print_r($your_array, true); 
    
    $arraystring = '
    '.print_r($your_array, true).'
    ';

    Or you could mix many arrays and vars if you do this

    ob_start();
    print_r($var1);
    print_r($arr1);
    echo "blah blah";
    print_r($var2);
    print_r($var1);
    $your_string_var = ob_get_clean();
    

提交回复
热议问题