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

Posted by Ken Robinson on 11/16/85 11:31

Peter Jay Salzman wrote:
> 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?

$str = implode(',',$myHobbits);

Ken

 

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

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