Re: How to construct an associative and numeric indexable array [message #178278 is a reply to message #178277] |
Sat, 26 May 2012 11:00 |
Michael Fesser
Messages: 215 Registered: September 2010
Karma:
|
Senior Member |
|
|
.oO(Leonardo Azpurua)
> Ok... forget SQLSRV. It was just the source (not the object) of my question.
>
> Let's say I have an array $arr, constructed thus:
>
> $arr = array("one" => "X", "two"=>"Y", ..., "umpt" =>"ZZZZZ");
>
> so that I can get $arr["one"] or $arr["umpt"].
>
> Now, at some moment, I want to obtain the (n+1)th value in the array. I just
> can't write $arr[$n];
>
> I know I might write:
> $k = array_keys($arr);
> $x = $arr[$k[$n]];
>
> But when you use the array returned by sqlsrv_fetch_array, you can either
> write $arr["C1"] or $arr[0].
>
> Do you know how they do that?
Such an array contains all values twice. There's no direct way to access
an element with an associative key also by a numeric index. For doing
that you would have to loop through the array until you've reached the
element you want.
Micha
--
http://mfesser.de/blickwinkel
|
|
|