473,788 Members | 2,733 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get first and last items in array

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.

Any advice would be appreciated.
Nov 15 '07 #1
3 45283
On Fri, 16 Nov 2007 00:15:52 +0100, mtuller <mi******@gmail .comwrote:
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
Nov 15 '07 #2
Yes - how dare a user ask for php help on a php newsgroup .
<comp.lang.ph p>
<Rik Wasmus>
<Fri, 16 Nov 2007 00:19:06 +0100>
<op************ ***@metallium.l an>
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.....

Nov 16 '07 #3
On Fri, 16 Nov 2007 14:00:23 +0100, Krustov <me@privacy.net wrote:
<comp.lang.ph p>
<Rik Wasmus>
<Fri, 16 Nov 2007 00:19:06 +0100>
<op************ ***@metallium.l an>
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.....
...and the answer was below that line..
Yes - how dare a user ask for php help on a php newsgroup .
What?

I stated: Read The Fine Manual, for instane, when working with arrays, one
would think to look at the array functions, <http://nl2.php.net/array>.
Try to find to find the text 'first' and 'last' on that page (two terms
the op literally used), and he'd have the answer.

Stating this could be easily found in the manual, and encouraging posters
to use it, helps them more in the long run then just easy answers.

Please don't toppost.
--
Rik Wasmus
Nov 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
901
by: Droopy | last post by:
Hi, I show some events to user in the GUI. I am using a listbox but I don't know if it is the best choice. I would like to show only n last events. Should I, as soon as n items are displayed, remove the first one and add the new one ? Thanks in advance for your help.
3
14015
by: Tony | last post by:
I have this code: Dim elementi() As String = Split(book, "pages") I have to do remove first item from array elementi ... any help? Thanks
0
1758
by: bdtmike | last post by:
I'm using the GridView control and have the Mode of the Pager set to "NumericFirstLast". However, when there are several pages to display, the pager shows only page numbers--and no First/Last buttons. First of all, is this a bug or am I doing something stupid? Secondly, can I override the page numbers using my own template? I'm using the latest Visual Studio 2005 Thanks.
8
1595
by: Jared.Holsopple | last post by:
Hi all, I have a dynamically allocated array of doubles in VC++ .NET. When I view the array in the watch window with "arrayName, 10", it displays the correct value for arrayName, but arrayName through arrayName are all zeros. Note that arrayName is actually double*, and not double. When I print out the array to the screen using printf, the correct (non-zero) values are displayed. I'd rather not dump a bunch of
2
2527
by: Tony Ciconte | last post by:
Does anyone know of or have any VBA code or similar logic that can help distinguish similar first/last name combinations? For example, we would like to prompt the user of a possible match when any of the first/last names Robert Smith, or Bob Smith, or Robt. Smith are used during data entry. All that is necessary is to alert the user so that they can review any appropriate existing records. We have done several google searches without any...
2
9897
by: Janick Bernet | last post by:
I just stumbled upon this olap function and wondered why the "NULLS FIRST/LAST" clause is not possible in normal order by but only using row_number() over(). Sure, I can do a SELECT *, row_number() over(ORDER BY col1 ASC NULLS FIRST) AS rn FROM tab1 ORDER BY rn to get what I want, but its awfully complicated. (Interestingly, the optimizer rewrites above order by in an ugly ORDER BY CASE WHEN col1 is NULL THEN 0 ELSE 1, col1) Anyone...
8
2002
by: gregpinero | last post by:
I'm running code via the "exec in context" statement within a much larger program. What I would like to do is capture any possible errors and show a pretty traceback just like the Python interactive interpreter does, but only show the part of the traceback relating to the code sent to exec. For example here is the code I'm using: try: exec code
4
4562
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first element so append a comma
2
2615
Claus Mygind
by: Claus Mygind | last post by:
I create an array like this $dispArray = array ("FIRST","LAST","name","ID","DIRECTPHON","MOBILE","MRMRS","myKey"); I search on the array like this: if(array_search ( $key , $searchArray )){....}
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10370
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10113
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.