Jump to content

Loop through variable and separate items into unique variables


defroster

Recommended Posts

Hello,

 

If I have this string:

 

$tags="baseball glove face" (this can vary from 1 to 15 different words)

 

how would i loop through and divide these into different

 

$tag1=baseball

$tag2=glove

$tag3=face

.. and so on (if more words)

 

Thanks for help

Didn't know you wanted to know how to loop. This is shorter:

 

$tags = $row['tags'];
foreach(str_word_count($tags, 1) as $value) {
   echo '<a href="search.php?q="'.$value.'">'.$value.'</a>';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.