Afficher un message
Vieux 27/03/2008, 01h34   #2
Jeremy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Access non-numerically indexed array by their order number

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
  Réponse avec citation
 
Page generated in 0,04491 seconds with 9 queries