Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1908618.nuHmqJ5PAb@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 27 May 2012 00:31:31 +0200 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <4od1s7lf3ach6e28sqh9gs5d02u7oqcpmj@mfesser.de> Followup-To: comp.lang.php MIME-Version: 1.0 Lines: 55 NNTP-Posting-Date: 27 May 2012 00:31:32 CEST NNTP-Posting-Host: 20248a1b.newsspool4.arcor-online.net X-Trace: DXC=^3R\GnlPV3?kUFX=Y?aLP;4IUKK0U@3`]Ai;Bf2iiV5jBQOAj0 X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.php:6203 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 ) PointedEars -- > If you get a bunch of authors […] that state the same "best practices" > in any programming language, then you can bet who is wrong or right... Not with javascript. Nonsense propagates like wildfire in this field. -- Richard Cornford, comp.lang.javascript, 2011-11-14