a1ias Posted June 24, 2006 Share Posted June 24, 2006 Hi guysI have an associative array e.g. [!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]Array( [item1] => 4 [item2] => 3 [item3] => 6 )[!--colorc--][/span][!--/colorc--]I'm trying to convert that array to a string format; something like:"item1 - 4, item2 - 3, item3 - 6"and then assign that string to a variable to be used in a mail() $body for example.I believe it should/can be done using the explode() function but I've tried for a couple hours now without success so I've decided to ask the pro's :)Could anyone give me a hint or a method on the easiest/most efficient way to do this?Many thanks in advancea1ias Quote Link to comment https://forums.phpfreaks.com/topic/12791-solved-beginner-associative-array-to-string/ Share on other sites More sharing options...
a1ias Posted June 24, 2006 Author Share Posted June 24, 2006 Solved this by building the string using the foreach loop:[code]foreach($myarray as $key => $value) {$body .= "$key - $value,";}echo $body;[/code] Quote Link to comment https://forums.phpfreaks.com/topic/12791-solved-beginner-associative-array-to-string/#findComment-49015 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.