SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    String Function Question

    I have an array, $names, that looks like this:

    $names = array("Joe", "Jill", "Bill);

    I've used the following code to list the contents of the above array:

    <?
    if (isset($names)){
    echo ("Here's your list of names: ");
    foreach ($names as $x)
    echo "($x, ");
    }
    ?>

    And here's what I get:

    Joe, Jill, Bill,

    What I need is the above string without the last comma. Is there a string function that will strip the last comma from the string? Or is there a way to modify the above code to accomplish this?

    Your thoughts will be appreciated.

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here ya go. implode() the array:

    PHP Code:
    echo implode(', '$names); 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dr_Larry.

    That's exactly what I needed.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •