Reply to Re: Newbie array question

Your name:

Reply:


Posted by NC on 10/10/54 11:32

luke wrote:
>
> I have an idea like this....
>
> $array = array(red, blue, green );
>
> I want it to rpint out this
>
> 1red
> 2blue
> 3green
>
> but cannot figure out how to do it without going through and
> keying the array, can someone please put me out of my misery?

foreach ($array as $key=>$item) {
echo ($key+1), $item;
}

Note that by default, elements of an array in PHP are numbered starting
from zero, hence, ($key+1) in the echo statement.

Cheers,
NC

[Back to original 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

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