473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Retrieving previous array item

I have an array. The array key is the id of the item (for example
categories[91], 91 is the ID of the category) all ID are not exactly in
date order, but they're added to the array in date order, how do I find
the previous (in the sense of when it was added) array entry of, for
example category['91']?

--

Belmin Fernandez

Visit: http://www.belminfernandez.com/homepage
Email: belminf at gmail period com
Jul 17 '05 #1
6 2348
JDS
On Wed, 23 Feb 2005 17:48:05 +0000, Belmin wrote:
I have an array. The array key is the id of the item (for example
categories[91], 91 is the ID of the category) all ID are not exactly in
date order, but they're added to the array in date order, how do I find
the previous (in the sense of when it was added) array entry of, for
example category['91']?


How are items added to the array? I don't understand how, if "all ID are
not exactly in date order," the items are added in date order.

In any case, any solutions based on your current array will be unreliable.

To make your data reliable, you will need to add the date to the data
somehow. I suggest a 2D associative array along the lines of

$categories = array(
array( "id" => 91, "date_added" => "2005-02-23 10:30:33" )
, array( "id" => 92, "date_added" => "2005-02-23 12:19:52")
);

(the time stamp can be formatted however you wish)

Then you can actually do stuff with the real date value and be certain
that it is correct in comparison to other items in the array.

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #2
I noticed that Message-ID:
<pa****************************@example.invalid> from JDS contained the
following:
How are items added to the array? I don't understand how, if "all ID are
not exactly in date order," the items are added in date order.


Yeah, I wondered about that too...

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #3
What I meant to say, the ID's aren't in date order. So for example, ID
91 might actually be older than ID 10. And also, not all IDs are used so
an array could look like:

array[10]
array[91]
array[23]
array[49]
(and so on)

Though during creation, they're stacked in date order. Im not sure if
I'm being clear enough. What I ended up doing is doing an array_keys
function and going by the index of it's results. Is this the most
efficient way?

Written by "JDS" on 2/23/05 1:30p:
On Wed, 23 Feb 2005 17:48:05 +0000, Belmin wrote:

I have an array. The array key is the id of the item (for example
categories[91], 91 is the ID of the category) all ID are not exactly in
date order, but they're added to the array in date order, how do I find
the previous (in the sense of when it was added) array entry of, for
example category['91']?

How are items added to the array? I don't understand how, if "all ID are
not exactly in date order," the items are added in date order.

In any case, any solutions based on your current array will be unreliable.

To make your data reliable, you will need to add the date to the data
somehow. I suggest a 2D associative array along the lines of

$categories = array(
array( "id" => 91, "date_added" => "2005-02-23 10:30:33" )
, array( "id" => 92, "date_added" => "2005-02-23 12:19:52")
);

(the time stamp can be formatted however you wish)

Then you can actually do stuff with the real date value and be certain
that it is correct in comparison to other items in the array.


--

Belmin Fernandez

Visit: http://www.belminfernandez.com/homepage
Email: belminf at gmail period com
Jul 17 '05 #4
On Wed, 23 Feb 2005 19:28:14 GMT, Belmin <an*******@nospam.com> wrote:
What I meant to say, the ID's aren't in date order. So for example, ID
91 might actually be older than ID 10. And also, not all IDs are used so
an array could look like:

array[10]
array[91]
array[23]
array[49]
(and so on)

Though during creation, they're stacked in date order. Im not sure if
I'm being clear enough. What I ended up doing is doing an array_keys
function and going by the index of it's results. Is this the most
efficient way?


Try the end() function.

Jul 17 '05 #5
"Belmin" <an*******@nospam.com> wrote in message
news:iP*********************@twister.nyc.rr.com...
Though during creation, they're stacked in date order. Im not sure if
I'm being clear enough. What I ended up doing is doing an array_keys
function and going by the index of it's results. Is this the most
efficient way?


Nah, there isn't a efficient way to retrieve the previous item or index.
array_keys() followed by array_flip() is probably the most straight forward
way.
Jul 17 '05 #6
.oO(Chung Leong)
"Belmin" <an*******@nospam.com> wrote in message
news:iP*********************@twister.nyc.rr.com.. .
Though during creation, they're stacked in date order. Im not sure if
I'm being clear enough. What I ended up doing is doing an array_keys
function and going by the index of it's results. Is this the most
efficient way?


Nah, there isn't a efficient way to retrieve the previous item or index.


prev() exists. Only problem is that you can't explicitly set the
internal array pointer to a particular element.

Micha
Jul 17 '05 #7

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

Similar topics

8
by: asd | last post by:
I need to find the value/index of the previously selected item of a select list. That is, when the user selects an item from the list and a certain condition elsewhere in the form is not met, I...
13
by: RHPT | last post by:
I am wanting to capture the XML posted by an InfoPath form with .NET, but I cannot figure out how to capture the XML stream sent back by the InfoPath form. With Classic ASP, I could just create an...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
0
bmallett
by: bmallett | last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.