You are here: Re: get first and last items in array « PHP Programming Language « IT news, forums, messages
Re: get first and last items in array

Posted by mtuller on 11/16/07 15:02

On Nov 16, 4:00 am, Rob <ratkin...@tbs-ltd.co.uk> wrote:
> On Nov 15, 11:19 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
>
>
>
> > On Fri, 16 Nov 2007 00:15:52 +0100, mtuller <mitul...@gmail.com> wrote:
> > > I want to get the first record and last record in an array. I don't
> > > want any other records, but am not finding how to do it. What I am
> > > doing is pulling out information from a database, where the sql query
> > > would have a result much like this:
>
> > > 10
> > > 11
> > > 12
> > > 13
> > > 14
> > > 15
> > > 16
>
> > > And I want to grab the first and last items in the array, so in this
> > > case, 10 and 16.
>
> > RTFM.....
>
> > $first = reset($array);
> > $last = end($array);
>
> > For ranges, look at array_slice()/array_splice()/count()
> > --
> > Rik Wasmus- Hide quoted text -
>
> > - Show quoted text -
>
> I would think about changing your SQL statement to only select the
> first and last record, using ORDER_BY and LIMIT. If you have a lot of
> rows to load, it would be much more efficient.
>
> Rob.

Thanks. It hit me this morning that I was not looking for items in an
array, but in the rows returned. I will look into an SQL solution.

 

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

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