• support@answerspoint.com

How to convert an array to a string in PHP?

237

For an array like the one below; what would be the best way to get the array values and store them as a comma-separated string?

Array ( [0] => 1000,
        [1] => 1001,
        [2] => 1002,
        [3] => 1003,
        [4] => 1004,
        [5] => 1005,
        [6] => 1006,
        [7] => 1007,
        [8] => 1008,
        [9] => 1009,
        [10] => 1010,
        [11] => 1011,
        [12] => 1012,
        [13] => 1013,
        [14] => 1014,
        [15] => 1015,
        [16] => 1016,
        [17] => 1017,
        [18] => 1018,
        [19] => 1019,
        [20] => 1020,) 

 

  • PHP

  • asked 4 months ago
  • Gul Hafiz

1Answer


0

I would turn it into CSV form, like so:

$string_version = implode(',', $original_array)

You can turn it back by doing:

$destination_array = explode(',', $string_version)

 

  • answered 4 months ago
  • Community  wiki

Your Answer

    Facebook Share