I'm hacking together a style for wordpress and i'm while using following code to drag out data from the custom area with several values:

            <?php  $mykey_values = get_post_custom_values('services');
            foreach ( $mykey_values as $key => $value ) {
            echo "<span>$value, </span>";
            } ?>

I personally use a comma to seperate the outcomes, but I'm not going a comma following the last result. How do you circumvent this?

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

Edit: BTW, you do not make use of the loop if you are using this code.

Many different ways to get this done... the first I'm able to think about is rather than using echo, concatenate all of the results right into a string, then take away the last , character.

One other way is always to make use of a for loop rather than foreach after which iterate to how big $mykey_values - 1 after which print the final one with no ,. And I am sure others will publish different ways (maybe with real code too - my PHP is simply too rusty that i can risk a genuine code sample).

Easiest way is by using implode:

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