|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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' ); |
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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 |
|
#4
|
|||
|
|||
|
This is the way I'd do it
PHP Code:
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > First and Last array key |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|