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. Quote Link to comment 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); ?> Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.