Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6207
| From | Norman Peelman <npeelmandog@cfl.rr.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: How to construct an associative and numeric indexable array |
| Date | 2012-05-27 12:03 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <jptj7t$le0$1@dont-email.me> (permalink) |
| References | (2 earlier) <jpphes$6iq$1@dont-email.me> <jppkou$jug$1@dont-email.me> <jppm1b$p73$1@dont-email.me> <4od1s7lf3ach6e28sqh9gs5d02u7oqcpmj@mfesser.de> <jpqmkm$gil$1@dont-email.me> |
On 05/26/2012 09:43 AM, Leonardo Azpurua wrote:
> "Michael Fesser"<netizen@gmx.de> escribió en el mensaje
> news:4od1s7lf3ach6e28sqh9gs5d02u7oqcpmj@mfesser.de...
>> .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.
>
> So that's how they do it!
>
> I just checked and in fact count($row) yields twice the number of columns in
> the result set.
>
> And it is anything but appealing as a "general" solution.
>
> You also saved me from stumbling against "for ($n = 0; $n< count($row);
> $n++)", which would have happened sooner than later.
>
> Thanks!
>
At which point you would have stumbled upon the answer. :)
--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
How to construct an associative and numeric indexable array "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-25 18:49 -0430
Re: How to construct an associative and numeric indexable array Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-25 20:08 -0400
Re: How to construct an associative and numeric indexable array "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-25 22:39 -0430
Re: How to construct an associative and numeric indexable array Jerry Stuckle <jstucklex@attglobal.net> - 2012-05-26 00:04 -0400
Re: How to construct an associative and numeric indexable array "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-25 23:57 -0430
Re: How to construct an associative and numeric indexable array Michael Fesser <netizen@gmx.de> - 2012-05-26 13:00 +0200
Re: How to construct an associative and numeric indexable array "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-26 09:13 -0430
Re: How to construct an associative and numeric indexable array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-27 00:31 +0200
Re: How to construct an associative and numeric indexable array "Leonardo Azpurua" <leonardo@exmvps.org> - 2012-05-26 22:14 -0430
Re: How to construct an associative and numeric indexable array Norman Peelman <npeelmandog@cfl.rr.com> - 2012-05-27 12:12 -0400
Re: How to construct an associative and numeric indexable array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-05-27 19:48 +0200
Re: How to construct an associative and numeric indexable array Norman Peelman <npeelmandog@cfl.rr.com> - 2012-05-29 18:27 -0400
Re: How to construct an associative and numeric indexable array Norman Peelman <npeelmandog@cfl.rr.com> - 2012-05-27 12:03 -0400
csiph-web