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

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

    Convert array to a string in PHP:

    Use the PHP join function like this:

    $my_array = array(4,1,8);
    
    print_r($my_array);
    Array
    (
        [0] => 4
        [1] => 1
        [2] => 8
    )
    
    $result_string = join(',' , $my_array);
    echo $result_string;
    

    Which delimits the items in the array by comma into a string:

    4,1,8
    

提交回复
热议问题