You are here: repeating stuff except at the end points « PHP Programming Language « IT news, forums, messages
repeating stuff except at the end points

Posted by Peter Jay Salzman on 11/16/35 11:31

Consider:

$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?

Thanks!
Pete

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация