• The following code works fine, but I don’t want a comma after the last result. Any advice to getting rid of the last comma?

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

Viewing 1 replies (of 1 total)
  • I think this will work for you:

    <?php  $mykey_values = get_post_custom_values('services');
    $lastvalue = end($mykey_values);
    $lastkey = key($mykey_values);
    reset($mykey_values);
    $sep = ', ';
    foreach ( $mykey_values as $key => $value ) {
      if ($key == $lastkey) $sep = '';
       echo "<span>$value$sep</span>";
    }
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Remove comma after last result of custom field keys’ is closed to new replies.