• support@answerspoint.com

How to convert an array to a string in PHP?

1834

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 6 years 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 6 years ago
  • Community  wiki

Your Answer

    Facebook Share        
       
  • asked 6 years ago
  • viewed 1834 times
  • active 6 years ago

Best Rated Questions