Welcome Guest, Not a member yet? Register   Sign In
How to separate an array
#3

[eluser]CroNiX[/eluser]
before your foreach, do a print_r($row); I have a feeling your result is because the result from the database is one long string and not separate tags like you are expecting (from your code anyway).

If thats the case, in your foreach you can
Code:
$tags = array();
foreach($row as $tagstring)
{
    $tagline = explode(',', $tagstring);
    foreach($tagline as $tag)
    {
        $tags[] = '#' . trim($tag);
    }
}
//now all of your tags are in this array the way you want
printr($tags);

foreach($tags as $tag)
{
    echo "$tag<br />";
}

//#business
//#master
//#music
//...

$tagstring = implode(', ', $tags);
echo $tagstring;
//#business, #apples, #music...


Messages In This Thread
How to separate an array - by El Forum - 10-07-2010, 12:00 PM
How to separate an array - by El Forum - 10-07-2010, 12:41 PM
How to separate an array - by El Forum - 10-07-2010, 12:50 PM
How to separate an array - by El Forum - 10-07-2010, 12:51 PM
How to separate an array - by El Forum - 10-07-2010, 01:38 PM
How to separate an array - by El Forum - 10-07-2010, 01:55 PM
How to separate an array - by El Forum - 10-07-2010, 02:00 PM
How to separate an array - by El Forum - 10-07-2010, 02:03 PM
How to separate an array - by El Forum - 10-07-2010, 02:19 PM
How to separate an array - by El Forum - 10-07-2010, 02:30 PM
How to separate an array - by El Forum - 10-07-2010, 02:36 PM
How to separate an array - by El Forum - 10-07-2010, 02:46 PM
How to separate an array - by El Forum - 10-07-2010, 03:12 PM
How to separate an array - by El Forum - 10-07-2010, 05:51 PM
How to separate an array - by El Forum - 10-07-2010, 11:48 PM
How to separate an array - by El Forum - 10-08-2010, 09:55 AM
How to separate an array - by El Forum - 10-08-2010, 11:26 AM
How to separate an array - by El Forum - 10-08-2010, 10:54 PM
How to separate an array - by El Forum - 10-09-2010, 12:06 AM
How to separate an array - by El Forum - 10-18-2010, 09:22 AM
How to separate an array - by El Forum - 10-18-2010, 10:20 AM
How to separate an array - by El Forum - 10-19-2010, 11:08 AM
How to separate an array - by El Forum - 10-20-2010, 09:58 PM
How to separate an array - by El Forum - 10-20-2010, 10:54 PM
How to separate an array - by El Forum - 10-21-2010, 11:40 AM
How to separate an array - by El Forum - 10-21-2010, 11:48 AM
How to separate an array - by El Forum - 10-21-2010, 12:04 PM
How to separate an array - by El Forum - 10-21-2010, 12:49 PM
How to separate an array - by El Forum - 10-21-2010, 12:53 PM
How to separate an array - by El Forum - 10-21-2010, 02:07 PM
How to separate an array - by El Forum - 10-21-2010, 02:23 PM
How to separate an array - by El Forum - 10-21-2010, 03:07 PM
How to separate an array - by El Forum - 10-21-2010, 04:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB