Jump to content

Explode Spilt & Arrays


Recommended Posts

Hey Guys,

 

I've got this code:

while($row = mysql_fetch_array($result))
	{
		 $tagstringarray[]=$row['mycolumn'];

	}
 }

 foreach ($tagstringarray as $tag) {
	$pieces[] = explode(",", $tag);
 }

  foreach ($pieces as $tag) {
	echo $tag . "<br/>";
 }
	print_r ($pieces);

 

My database has a number of records which are tags, so are seperated by commas. eg. "tag1, tag2, tag3", but some just contain 1 tag eg "tag1".

 

This seems to put it as (presumably) a multi dimensional array, any ideas how I can return it all to one single dimensional array?

 

Thanks.

Link to comment
Share on other sites

Why would you swap one for the other? If you don't wan't to explode this string, just don't use explode...

 

while($row = mysql_fetch_array($result)) {
  $tagstringarray[]=$row['mycolumn'];
}

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

Link to comment
Share on other sites

$tagString = '';
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
   $tags       = explode(',', $row['mycolumn']);
   $tagString .= implode('<br />', $tags) . '<br />';
}

echo $tagString;
var_dump($tagString);   

 

That work ok?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.