Rookie PHP question Rookie PHP question wordpress wordpress

Rookie PHP question


Best way is with implode:

echo('<span>' . implode('</span>, <span>', $mykey_values) . '</span>');


Many ways to do this... the first one I can think of is instead of using echo, concatenate all the results into a string, then remove the last , character.

Another way would be to use a for loop instead of foreach and then iterate to the size of $mykey_values - 1 and then print the last one without a ,. And I'm sure others will post other ways (maybe with real code too - my PHP is too rusty for me to risk a real code sample).


echo "<span>" . implode(',</span><span>',$mykey_values) . "</span>;

Edit: BTW, you don't use the loop if you use this code.