On Mon, 03 Nov 2003 10:46:21 +0000, Jon Kraft <jon@jonux.co.uk> wrote:
[color=blue]
>Glutinous <glutinosity@$yahoo$.co.uk> wrote:
>[color=green]
>> On Fri, 31 Oct 2003 10:00:57 +0000, Jon Kraft <jon@jonux.co.uk> wrote:
>>[color=darkred]
>>>Glutinous <glutinosity@$yahoo$.co.uk> wrote:
>>>
>>>> I've been studying this for hours, searching the www & usenet, and
>>>> still can't figure out why 'each' returns an array of four key/value
>>>> pairs, when it looks like just two pairs would suffice...
>>>>
>>>> That is, it looks to me like
>>>> [0] & ['key']
>>>> are the same, and also
>>>> [1] & ['value'],
>>>> so what's the point of duplicating them?
>>>
>>>Where do you get your array from?
>>>
>>>Do you use mysql_fetch_array() by any chance? By default it returns both
>>>an indexed and an associative array.[/color]
>>
>> <?php
>> $foo = array("FirstKey" => "1stValue");
>> $bar = each($foo);
>> print_r($bar);
>> ?>
>>
>> Which produces:
>> Array ( [1] => 1stValue [value] => 1stValue [0] => FirstKey [key] =>
>> FirstKey )[/color]
>
>Hi,
>
>That's just default behaviour of each().
>
><quote>
>Returns the current key and value pair from the array array and advances the
>array cursor. This pair is returned in a four-element array, with the keys
>0, 1, key, and value. Elements 0 and key contain the key name of the array
>element, and 1 and value contain the data.
></quote>
>
>
http://uk.php.net/manual/en/function.each.php[/color]
Thank you again, Jon...
So we have two pairs of data; and in each pair, one component is
effectively redundant.
That is, there is no use for [0] and [1], as 'key' and 'value' provide
all the info that's available or useful?
Weird kinda default behaviour to set up, though, isn't it? I could
understand it if, say, [0] always held a numerical key, so no matter
what you called it, it was always possible to refer to [0] to get a
key/value pair's position, or something.
Oh well...
Thanks again for the responses!