Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- repeating stuff except at the end points
- Peter Jay Salzman
November 7, 2005, 5:52 pm
rate this thread
$myHobbits = array( 'frodo', 'bilbo', 'merry', 'pippin' );
I'd like generate the string:
"frodo, bilbo, merry, pippin"
One way of doing this would be:
$str = '';
foreach ( $myHobbits as $hobbit )
$str .= "$hobbit, ";
$str = rtrim( $str, ", " );
Does anyone know how to do this in less than 4 lines of code?