PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 11th, 2008, 12:04 AM
nikko50 nikko50 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 390 nikko50 User rank is Corporal (100 - 500 Reputation Level)nikko50 User rank is Corporal (100 - 500 Reputation Level)nikko50 User rank is Corporal (100 - 500 Reputation Level)nikko50 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 23 h 11 m 58 sec
Reputation Power: 7
First and Last array key

Hi all. How can I return the first and last key of an array if the array looks like below?

Code:
$orderArray = array(
  '11111',
  '22222',
  '33333',
  '44444',
  '55555',
  '66666',
  '77777',
  '88888',
  '99999'
  

);

Reply With Quote
  #2  
Old May 11th, 2008, 12:31 AM
requinix's Avatar
requinix requinix is offline
No strings attached
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 4,627 requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)requinix User rank is General 14th Grade (Above 100000 Reputation Level)  Folding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate FolderFolding Points: 77202 Folding Title: Intermediate Folder
Time spent in forums: 3 Months 3 Weeks 3 Days 20 h 51 m 36 sec
Reputation Power: 1898
Send a message via MSN to requinix
Use reset() to move to the beginning of the array.
Use end() to move to the end of the array.
Use key() to get the key of the currently "selected" item in an array.
Use the PHP manual if you aren't sure about those three (my sig, red link).
__________________
How to ask a question

Reply With Quote
  #3  
Old May 11th, 2008, 12:03 PM
Fuial Fuial is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 6 Fuial New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 43 m 31 sec
Reputation Power: 0
the first of the array is $yourarray[0]
and the last is $yourarray[length($yourarray)-1]

There are a lot of ways to do this.

In my opinion the best is with the iterators, but i dont want to expain it now because i have no time :P

Reply With Quote
  #4  
Old May 11th, 2008, 12:18 PM
thedude2010 thedude2010 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 454 thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level)thedude2010 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 h 44 m 55 sec
Reputation Power: 55
This is the way I'd do it
PHP Code:
 $last=$array[count($array)-1


Quote:
Originally Posted by Fuial
the first of the array is $yourarray[0]
and the last is $yourarray[length($yourarray)-1]

There are a lot of ways to do this.

In my opinion the best is with the iterators, but i dont want to expain it now because i have no time :P

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > First and Last array key


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT