|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi all,
For example if I have $array = array( 'assd' => 21, 's9aso' => 1267, 2 => 129 ); And I need to access 2nd element in the array, not the element with the key 2, but 's9aso' => 1267. I know array_splice works that way, for example array_slice($array, 1) will return two last elements, ie starting at 2nd element (id=1). Is there a way to access an array that way, by some internal id number which always starts at 0 etc? I could use array_keys to get array( 0 => 'assd', 1 => 's9aso', 2 => 2 ) But other than that? Thanks! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Mikhail Kovalev wrote:
> Hi all, > > For example if I have > $array = array( > 'assd' => 21, > 's9aso' => 1267, > 2 => 129 > ); > > And I need to access 2nd element in the array, not the element with > the key 2, but 's9aso' => 1267. > I know array_splice works that way, for example array_slice($array, 1) > will return two last elements, ie starting at 2nd element (id=1). > Is there a way to access an array that way, by some internal id number > which always starts at 0 etc? I could use array_keys to get > array( > 0 => 'assd', > 1 => 's9aso', > 2 => 2 > ) > > But other than that? > > Thanks! What's wrong with array_slice? list($second) = array_slice($array, 1, 1, true); A little round about, but it works. Jeremy |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 27 Mar, 00:34, Jeremy <jer...@pinacol.com> wrote:
> Mikhail Kovalev wrote: > > Hi all, > > > For example if I have > > $array = array( > > 'assd' => 21, > > 's9aso' => 1267, > > 2 => 129 > > ); > > > And I need to access 2nd element in the array, not the element with > > the key 2, but 's9aso' => 1267. > > I know array_splice works that way, for example array_slice($array, 1) > > will return two last elements, ie starting at 2nd element (id=1). > > Is there a way to access an array that way, by some internal id number > > which always starts at 0 etc? I could use array_keys to get > > array( > > 0 => 'assd', > > 1 => 's9aso', > > 2 => 2 > > ) > > > But other than that? > > > Thanks! > > What's wrong with array_slice? > > list($second) = array_slice($array, 1, 1, true); > > A little round about, but it works. > > Jeremy True, but the result is an array of length 1, not the value. But shouldn't it be anything faster? |
|
![]() |
| Outils de la discussion | |
|
|