Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6206
| From | "Leonardo Azpurua" <leonardo@exmvps.org> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: How to construct an associative and numeric indexable array |
| Date | 2012-05-26 22:14 -0430 |
| Organization | A noiseless patient Spider |
| Message-ID | <jps4d7$mcb$1@dont-email.me> (permalink) |
| References | (3 earlier) <jppkou$jug$1@dont-email.me> <jppm1b$p73$1@dont-email.me> <4od1s7lf3ach6e28sqh9gs5d02u7oqcpmj@mfesser.de> <jpqmkm$gil$1@dont-email.me> <1908618.nuHmqJ5PAb@PointedEars.de> |
"Thomas 'PointedEars' Lahn" <PointedEars@web.de> escribió en el mensaje news:1908618.nuHmqJ5PAb@PointedEars.de... > Leonardo Azpurua wrote: > >> "Michael Fesser" [wrote]: >>> .oO(Leonardo Azpurua) >>>> 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. > > However, the array can also be created so that the value with the numeric > key is a reference to the value with the non-numeric key, or vice-versa. > Thereby the memory footprint of the array may be reduced; at least, > inconsistencies are avoided: > > $ php -v > PHP 5.3.10-1 (cli) (built: Feb 3 2012 10:03:01) > Copyright (c) 1997-2012 The PHP Group > Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies > with XCache v1.3.2, Copyright (c) 2005-2011, by mOo > with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans > with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH > > $ phpsh -c > php> $a = array(); $a['foo'] = 'bar'; $a[0] =& $a['foo']; print_r($a); > Array > ( > [foo] => bar > [0] => bar > ) > > php> $a[0] = 'baz'; print_r($a); > Array > ( > [foo] => baz > [0] => baz > ) A nice solution, thanks! --
Back to comp.lang.php | Previous | Next — Previous in thread | Next 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