ale1981 Posted March 17, 2008 Share Posted March 17, 2008 If I have an array similar to; Array ( [0] => 0010 [1] => 0020 [2] => 0030 [3] => 0040 [4] => 0050 [5] => 0060 ) How can i convert that array to a string, so the string will be like; "0010", "0020", "0030", "0040", "0050", "0060" Notice the "," is missing from the last part of the array. If the array has only one entry then it would be; "0010" Any help appreciated. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/96536-create-string-from-array/ Share on other sites More sharing options...
obsidian Posted March 17, 2008 Share Posted March 17, 2008 What are you doing with the string? If you are writing this to a file in order to create an Excel readable CSV file, check out the fgetcsv() and fputcsv() functions. Otherwise, you'd need something like this: <?php $arr = array('0010', '0020', '0030', '0040', '0050', '0060'); foreach ($arr as $k => $v) { $arr[$k] = '"{$v}"'; } echo implode(',' $arr); ?> Link to comment https://forums.phpfreaks.com/topic/96536-create-string-from-array/#findComment-493997 Share on other sites More sharing options...
ale1981 Posted March 17, 2008 Author Share Posted March 17, 2008 Thanks obsidian, works great; foreach ($groupID as $k => $v) { $groupID[$k] = '"' .$v. '"'; } $groupNos = implode(',', $groupID); echo $groupNos; Link to comment https://forums.phpfreaks.com/topic/96536-create-string-from-array/#findComment-494010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.