FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » How to construct an associative and numeric indexable array
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: How to construct an associative and numeric indexable array [message #178287 is a reply to message #178285] Sun, 27 May 2012 16:12 Go to previous messageGo to previous message
Norman Peelman is currently offline  Norman Peelman
Messages: 126
Registered: September 2010
Karma:
Senior Member
On 05/26/2012 10:44 PM, Leonardo Azpurua wrote:
> "Thomas 'PointedEars' Lahn"<PointedEars(at)web(dot)de> escribió en el mensaje
> news:1908618(dot)nuHmqJ5PAb(at)PointedEars(dot)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!
>
> --
>
>

Solution to what? Thomas created that array, not SQLSRV... what you
are looking for is here:

http://us.php.net/manual/en/sqlsrv.constants.php

.... the top three items are of interest.

and examples:

http://us.php.net/manual/en/function.sqlsrv-fetch-array.php



--
Norman
Registered Linux user #461062
-Have you been to www.php.net yet?-
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Overriding PHP INI Setting session.use_trans_sid=0
Next Topic: Saving a three-dimensional array to the mysql database.
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Sep 28 22:53:56 GMT 2024

Total time taken to generate the page: 0.04820 seconds